package com.xiaochong.tir.api.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.service.common.config.oss.OSSTool;
import com.xiaochong.service.common.config.redis.RedisServer;
import com.xiaochong.tir.api.component.HbaseBaseQueryComponent;
import com.xiaochong.tir.api.component.RedisCacheComponent;
import com.xiaochong.tir.api.util.ListSortUtil;
import com.xiaochong.tir.api.util.StringUtil;
import com.xiaochong.tir.common.data.Bo.CurrencyGainPriceRedisBo;
import com.xiaochong.tir.common.data.hbasepo.*;
import com.xiaochong.tir.common.data.mapper.*;
import com.xiaochong.tir.common.data.mapperSearchResult.ExchangeTransactionpair;
import com.xiaochong.tir.common.data.po.*;
import com.xiaochong.tir.common.data.po.ExchangeInfoVo;
import com.xiaochong.tir.common.data.redisPo.KActionTotalPo;
import com.xiaochong.tir.common.data.vo.*;
import com.xiaochong.tir.common.exception.hbase.HbaseCloseExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseConnectionExcetion;
import com.xiaochong.tir.common.exception.hbase.HbaseGetTableExcetion;
import com.xiaochong.tir.common.util.*;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * 此类为[基础代码]自动生成,已经拥有基本的增删改成操作
 * <其他请自行扩展>
 * @author cx
 * @time 2018-04-26 09:56
 *
 */
@Service
public class ExchangeInfoService {


    @Autowired
    private ExchangeInfoMapper exchangeInfoDao;

    @Autowired
    private ListedCompanyIndexMapper listedCompanyIndexMapper;

    @Autowired
    private NonListedCompanyIndexMapper nonListedCompanyIndexMapper;

    @Autowired
    private ConceptCategoryMapper conceptCategoryMapper;

    @Autowired
    private RedisServer redisServer;

    @Autowired
    private RedisCacheComponent redisCacheComponent;

    @Autowired
    private CurrencyInfoMapper currencyInfoMapper;

    @Autowired
    private ConceptCategoryMapper conceptCategoryMapperp;

    @Autowired
    private HbaseBaseQueryComponent hbaseBaseQueryComponent;

    @Autowired
    private CurrencyIndustryCategoryMapper currencyIndustryCategoryMapper;

    @Autowired
    private SyResearchReportMapper syResearchReportMapper;

    @Autowired
    private SyResearchReportFileMapper syResearchReportFileMapper;

    @Autowired
    private SyRotationMapMapper syRotationMapMapper;

    @Autowired
    private SyChannelsMapper syChannelsMapper;

    @Autowired
    private TransactionPairMapper transactionPairMapper;

    @Autowired
    private ExchangeTransactionpairMiddleMapper exchangeTransactionpairMiddleMapper;

    @Autowired
    private KLineMapper kLineMapper;

    @Autowired
    private ImmortalsService immortalsService;

    @Autowired
    private OSSTool ossTool;

    @Autowired
    private OssImageUtil ossImageUtil;

    @Autowired
    private KLineTradesService kLineTradesService;
    @Autowired
    private ShelSelectService shelSelectService;
    @Autowired
    private SelfSelectedMapper selfSelectedMapper;
    /**
     * 新增
     *
     * @param entity
     * @param session
     */
    public int insertSelective(ExchangeInfo entity) {
        return this.exchangeInfoDao.insertSelective(entity);
    }

    /**
     * 批量新增
     *
     * @param list
     * @param session
     */
    public void insertBatch(List<ExchangeInfo> list) {

        this.exchangeInfoDao.insertBatch(list);


    }

    /**
     * 根据主键修改单条数据
     *
     * @param entity
     * @param session
     */
    public int updateByPrimaryKey(ExchangeInfo entity) {
        return this.exchangeInfoDao.updateByPrimaryKey(entity);
    }

    /**
     * 根据主键批量修改数据
     *
     * @param list
     * @param session
     */
    public void updateBatch(List<ExchangeInfo> list) {

        this.exchangeInfoDao.updateBatch(list);


    }

    /**
     * 根据主键查询单条数据
     *
     * @param id
     */
    public ExchangeInfo selectByPrimaryKey(Integer id) {
        return this.exchangeInfoDao.selectByPrimaryKey(id);
    }

    /**
     * 根据条件查询单条记录
     *
     * @param entity
     */
    public ExchangeInfo selectByEntity(ExchangeInfo entity) {
        return this.exchangeInfoDao.selectByEntity(entity);
    }

    /**
     * 交易所指数
     *
     * @param entity
     */

    public ApiResultVo selectByEntityList(ExchangeInfo entity) {
        ApiResultVo resultVo = new ApiResultVo();
        try {
            List<ExchangeInfo> list = null;
            try {
                entity.setEnableFlag(true);
                entity.setDeleteFlag(false);
                list = exchangeInfoDao.selectByEntityList(entity);
            } catch (Exception e) {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                return resultVo;
            }
            List<ExchangeIndexVo> exchangeList = new ArrayList<ExchangeIndexVo>();
            for (int i = 0; i < list.size(); i++) {
                ExchangeInfo info = list.get(i);
                ExchangeIndexVo vo = new ExchangeIndexVo();
                vo.setRank(i + 1);
                vo.setIndex(StringUtil.getDoubleOne(info.getIndex()));
                vo.setUrl(info.getOfficialWebsiteAddres());
                vo.setExchange(info.getExchangeName());
                vo.setAddress(info.getCountryName());
                exchangeList.add(vo);
            }

            //分页
            Object result=null;
            if (exchangeList.size()>0){
                result=StringUtil.pageBean( exchangeList,entity.getPageIndex(),entity.getPageSize() );
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setData(result);
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setPages(entity.getPageSize());
            resultVo.setTotal(exchangeList.size());
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("交易所指数", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * 根据条件查询Id
     *
     * @param entity
     */
    public Integer selectById(ExchangeInfo entity) {
        return this.exchangeInfoDao.selectById(entity);
    }

    /**
     * 根据条件查询Ids
     *
     * @param entity
     */
    public List<Integer> selectByIds(ExchangeInfo entity) {
        return this.exchangeInfoDao.selectByIds(entity);
    }

    /**
     * 根据主键删除单条记录
     *
     * @param id
     */
    public void deleteByPrimaryKey(Integer id) {
        this.exchangeInfoDao.deleteByPrimaryKey(id);
    }

    /**
     * 根据主键删除多条记录
     *
     * @param list
     */
    public void deleteBatch(List<Integer> list) {
        this.exchangeInfoDao.deleteBatch(list);
    }

    /**
     * 根据某些条件删除
     *
     * @param entity
     */
    public void deleteBatch(ExchangeInfo entity) {
        this.exchangeInfoDao.deleteByEntity(entity);
    }

    /**
     * 首页前8交易所指数
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo selectByEntityTop(ExchangeInfo entity) {
        ApiResultVo resultVo = new ApiResultVo();
        try {
            entity.setEnableFlag(true);
            entity.setDeleteFlag(false);
            List<ExchangeInfo> list = exchangeInfoDao.selectByEntityTop(entity);
            List<ExchangeIndexVo> exchangeList = new ArrayList<ExchangeIndexVo>();
            for (int i = 0; i < list.size(); i++) {
                ExchangeInfo info = list.get(i);
                ExchangeIndexVo vo = new ExchangeIndexVo();
                vo.setRank(i + 1);
                vo.setIndex(StringUtil.getDoubleOne(info.getIndex()));
                vo.setUrl(info.getOfficialWebsiteAddres());
                vo.setExchange(info.getExchangeName());
                vo.setAddress(info.getCountryName());
                exchangeList.add(vo);
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(exchangeList);
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("首页前8交易所指数", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * A股上市公司区块链指数
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo selectBlockIndex(ListedCompanyIndex listedCompanyIndex) {
        ApiResultVo resultVo = new ApiResultVo();

        try {
            List<ListedCompanyIndex> list = null;
            try {
                listedCompanyIndex.setEnableFlag(true);
                listedCompanyIndex.setDeleteFlag(false);
                list = listedCompanyIndexMapper.selectByEntityList(listedCompanyIndex);
            } catch (Exception e) {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
                return resultVo;
            }
            List<ABlockIndexVo> exchangeList = new ArrayList<ABlockIndexVo>();
            for (int i = 0; i < list.size(); i++) {
                ListedCompanyIndex index = list.get(i);
                ABlockIndexVo vo = new ABlockIndexVo();
                vo.setRank(i + 1);
                vo.setStockCode(index.getSecuritiesCode());
                vo.setProjectProgress(index.getProjectProgress().toString());
                vo.setTeamBuilding(index.getTeamBuilding().toString());
                vo.setOutreachCooperation(index.getOutreachCooperation().toString());
                vo.setCapitalInvestment(index.getCapitalInvestment().toString());
                vo.setCompanyMarket(index.getCompanyMarketValue().toString());
                vo.setWindConcept(index.getWindConcept().toString());
                vo.setStockCode(index.getSecuritiesCode());
                vo.setIndex(StringUtil.getDoubleOne(index.getIndex()));
                vo.setCompany(index.getSecuritiesAbbreviation());
                vo.setTotalImplementation(index.getImplementationSubtotal().toString()); //实施合计
                vo.setTotalCompany(index.getCompanyItselfSubtotal().toString()); //公司自身合计
                vo.setTotalStrategy(index.getStrategicLevelSubtotal().toString()); //战略层面小计
                vo.setStrategicLevel(index.getStrategicLevel().toString()); //战略层面

                exchangeList.add(vo);
            }

            //分页
            Object result=null;
            if (exchangeList.size()>0){
                result=StringUtil.pageBean( exchangeList,listedCompanyIndex.getPageIndex(),listedCompanyIndex.getPageSize() );
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(result);
            resultVo.setPages(listedCompanyIndex.getPageSize());
            resultVo.setTotal(exchangeList.size());
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("A股上市公司区块链指数", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * 首页A股上市公司区块链指数
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo selectBlockIndexTop() {
        ApiResultVo resultVo = new ApiResultVo();

        try {
            List<ListedCompanyIndex> list = null;

            try {
                ListedCompanyIndex listedCompanyIndex = new ListedCompanyIndex();
                listedCompanyIndex.setEnableFlag(true);
                listedCompanyIndex.setDeleteFlag(false);
                list = listedCompanyIndexMapper.selectByEntityListTop(listedCompanyIndex);
            } catch (Exception e) {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                return resultVo;
            }
            List<ABlockIndexVo> exchangeList = new ArrayList<ABlockIndexVo>();
            for (int i = 0; i < list.size(); i++) {
                ListedCompanyIndex index = list.get(i);
                ABlockIndexVo vo = new ABlockIndexVo();
                vo.setRank(i + 1);
                vo.setStockCode(index.getSecuritiesCode());
                vo.setProjectProgress(index.getProjectProgress().toString());
                vo.setTeamBuilding(index.getTeamBuilding().toString());
                vo.setOutreachCooperation(index.getOutreachCooperation().toString());
                vo.setCapitalInvestment(index.getCapitalInvestment().toString());
                vo.setCompanyMarket(index.getCompanyMarketValue().toString());
                vo.setWindConcept(index.getWindConcept().toString());
                vo.setStockCode(index.getSecuritiesCode());
                vo.setIndex(StringUtil.getDoubleOne(index.getIndex()));
                vo.setCompany(index.getSecuritiesAbbreviation());
                exchangeList.add(vo);
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(exchangeList);
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("首页A股上市公司区块链指数", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * 非上市公司区块链指数
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo selectWBlockIndex(NonListedCompanyIndex nonListedCompanyIndex) {
        ApiResultVo resultVo = new ApiResultVo();

        try {
            nonListedCompanyIndex.setEnableFlag(true);
            nonListedCompanyIndex.setDeleteFlag(false);
            List<NonListedCompanyIndex> list = nonListedCompanyIndexMapper.selectByEntityList(nonListedCompanyIndex);
            List<WBlockIndex> wbList = new ArrayList<WBlockIndex>();
            for (int i = 0; i < list.size(); i++) {
                NonListedCompanyIndex index = list.get(i);
                WBlockIndex wb = new WBlockIndex();
                wb.setRank(i + 1);
                wb.setPlatform(index.getPlatformName());
                wb.setCompany(index.getEnterpriseName());
                wb.setOnlineTime(index.getOnlineTime());
                wb.setCity(index.getCityName());
                wb.setIndex(StringUtil.getDoubleOne(index.getIndex()));

                wbList.add(wb);
            }

            //分页
            Object result=null;
            if (wbList.size()>0){
                result=StringUtil.pageBean( wbList,nonListedCompanyIndex.getPageIndex(),nonListedCompanyIndex.getPageSize() );
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(result);
            resultVo.setPages(nonListedCompanyIndex.getPageSize());
            resultVo.setTotal(wbList.size());
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("非上市公司区块链指数", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * 首页非上市公司区块链指数
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo selectWBlockIndexTop() {
        ApiResultVo resultVo = new ApiResultVo();

        try {
            List<NonListedCompanyIndex> list = null;

            try {
                NonListedCompanyIndex nonListedCompanyIndex = new NonListedCompanyIndex();
                nonListedCompanyIndex.setEnableFlag(true);
                nonListedCompanyIndex.setDeleteFlag(false);
                list = nonListedCompanyIndexMapper.selectByEntityListTop(nonListedCompanyIndex);
            } catch (Exception e) {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                return resultVo;
            }

            List<WBlockIndex> wbList = new ArrayList<WBlockIndex>();
            for (int i = 0; i < list.size(); i++) {
                NonListedCompanyIndex index = list.get(i);
                WBlockIndex wb = new WBlockIndex();
                wb.setRank(i + 1);
                wb.setPlatform(index.getPlatformName());
                wb.setCompany(index.getEnterpriseName());
                wb.setOnlineTime(index.getOnlineTime());
                wb.setCity(index.getCityName());
                wb.setIndex(StringUtil.getDoubleOne(index.getIndex()));

                wbList.add(wb);
            }

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(wbList);
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("首页非上市公司区块链指数", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * 概念行情
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo conceptIndex(ConceptCategory conceptCategory) {
        ApiResultVo resultVo = new ApiResultVo();

        try {
            List<ConceptQuotationVo> conList = new ArrayList<ConceptQuotationVo>();

            //redis
            String CONCEPT_QUOTATIONRESULTVO=redisServer.get( RedisKeysUtils.CONCEPT_QUOTATIONRESULTVO);
            if (CONCEPT_QUOTATIONRESULTVO!=null){
                LogTrace.info( "概念行情", "数据来源", "redis");
                conList=JSON.parseArray( CONCEPT_QUOTATIONRESULTVO,ConceptQuotationVo.class );
            }

            //hbase
            if (CONCEPT_QUOTATIONRESULTVO==null){
                conceptCategory.setEnableFlag(true);
                conceptCategory.setDeleteFlag(false);
                List<ConceptCategory> list = conceptCategoryMapper.selectByEntityList(conceptCategory);

                Long jStart = System.currentTimeMillis();
                for (int i = 0; i < list.size(); i++) {
                    ConceptQuotationVo vo = new ConceptQuotationVo();
                    String tirconcepe = redisServer.get(RedisKeysUtils.TIR_CONCEPT_INDEX + list.get(i).getId());
                    if (StringUtils.isNotBlank(tirconcepe)) {
                        ConceptIndex conceptIndex = JSON.parseObject(tirconcepe, ConceptIndex.class);
                        vo.setConceptId(list.get(i).getId()); //概念id
                        if (conceptIndex.getConceptIndex() != null)
                            vo.setQuotesIndex(conceptIndex.getConceptIndex().doubleValue()); //概念指数
                        vo.setConcept(list.get(i).getConceptCategoryName());  //概念分类名称
                        if (conceptIndex.getSumVolume24hCnyPrice() != null)
                            vo.setTurnover24h(StringUtil.getDoubleTwo(conceptIndex.getSumVolume24hCnyPrice().doubleValue())); //24小时成交额
                        if (conceptIndex.getAvgPercentChange24h() != null)
                            vo.setChange(conceptIndex.getAvgPercentChange24h().doubleValue()); //平均涨跌幅
                        if (conceptIndex.getRiseCount() != null) vo.setGainsCurrency(conceptIndex.getRiseCount()); //币上涨数
                        if (conceptIndex.getFallCount() != null) vo.setDeclineCurrency(conceptIndex.getFallCount()); //币下跌数
                        if (conceptIndex.getCount() != null) vo.setTotalCurrency(conceptIndex.getCount()); //币种总数

                        if (conceptIndex.getMaxPercentChange24hInfo() != null) {
                            CmcCurrencyInfo maxInfo = conceptIndex.getMaxPercentChange24hInfo();
                            if (maxInfo.getPercentChange24h() != null) {
                                double max = StringUtil.getDoubleTwo(Double.parseDouble(maxInfo.getPercentChange24h()));
                                vo.setStrongestCurrency(max + "");   //币种表现最强
                                vo.setStrongestSymbol(maxInfo.getSymbol());
                            }
                        }
                        if (conceptIndex.getMinPercentChange24hInfo() != null) {
                            CmcCurrencyInfo minInfo = conceptIndex.getMinPercentChange24hInfo();
                            if (minInfo.getPercentChange24h() != null) {
                                double min = StringUtil.getDoubleTwo(Double.parseDouble(minInfo.getPercentChange24h()));
                                vo.setWeakestCurrency(min + "");    //币种表现最弱
                                vo.setWeakestSymbol(minInfo.getSymbol());
                            }

                        }
                        if (vo.getQuotesIndex() == null) {
                            vo.setQuotesIndex(0.00);
                        }

                        if (vo.getChange() == null) {
                            vo.setChange(0.00);
                        }

                        if (vo.getTurnover24h() == null) {
                            vo.setTurnover24h(0.00);
                        }
                        conList.add(vo);
                    }
                }
                LogTrace.info( "概念行情", "数据来源", "hbase");
                //存入redis
                if(conList!=null||conList.size()>0){
                    redisServer.set( RedisKeysUtils.CONCEPT_QUOTATIONRESULTVO,JSON.toJSONString( conList ),3600L);
                }
            }

            //排序
            ListSortUtil util=new ListSortUtil();
            if (conceptCategory.getSortType() == 0) {
                util.mySort( conList, "quotesIndex", "desc" );
            }

            if (conceptCategory.getSortType() == 3) {
                util.mySort( conList, "quotesIndex", "asc" );
            }

            //根据24小时成交额度排序
            if (conceptCategory.getSortType() == 1) {
                util.mySort( conList, "turnover24h", "desc" );
            }

            if (conceptCategory.getSortType() == 4) {
                util.mySort( conList, "turnover24h", "asc" );
            }

            //根据平均涨幅升降序排列
            if (conceptCategory.getSortType() == 2) {
                util.mySort( conList, "change", "desc" );
            }

            if (conceptCategory.getSortType() == 5) {
                util.mySort( conList, "change", "asc" );
            }

            for (int i = 0; i < conList.size(); i++) {
                conList.get(i).setRank(i + 1);  //排名
            }

            //分页
            Object result=null;
            if(conList.size()>0){
                LogTrace.info( "概念行情", "分页", conceptCategory.getPageIndex()+"==="+conceptCategory.getPageSize());
                if(conceptCategory.getPageIndex()==null){
                    conceptCategory.setPageIndex( 1 );
                }
                if(conceptCategory.getPageSize()==null){
                    conceptCategory.setPageSize( 15 );
                }
                 result=StringUtil.pageBean( conList, conceptCategory.getPageIndex(),conceptCategory.getPageSize());
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(result);
            resultVo.setPages(conceptCategory.getPageSize());
            resultVo.setTotal(conList.size());
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("概念行情", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * 热门概念
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo hotConceptIndex() {
        ApiResultVo resultVo = new ApiResultVo();
        try {
            List<ConceptQuotationVo> conList = new ArrayList<ConceptQuotationVo>();

            ConceptCategory conceptCategory = new ConceptCategory();
            conceptCategory.setEnableFlag(true);
            conceptCategory.setDeleteFlag(false);
            List<ConceptCategory> list = conceptCategoryMapper.selectByEntityList(conceptCategory);

            Long jStart = System.currentTimeMillis();
            for (int i = 0; i < list.size(); i++) {
                ConceptQuotationVo vo = new ConceptQuotationVo();
                String tirconcepe = redisServer.get(RedisKeysUtils.TIR_CONCEPT_INDEX + list.get(i).getId());
                LogTrace.info("热门概念", "idandName", null);

                if (tirconcepe != null) {
                    ConceptCategory gory = list.get(i);
                    ConceptIndex conceptIndex = JSON.parseObject(tirconcepe, ConceptIndex.class);
                    if (gory != null) vo.setConceptId(gory.getId()); //概念id

                    if (gory != null && StringUtils.isNotBlank(gory.getConceptCategoryName()))
                        vo.setConcept(gory.getConceptCategoryName());  //概念分类名称
                    if (conceptIndex != null && conceptIndex.getAvgPercentChange24h() != null)
                        vo.setChange(conceptIndex.getAvgPercentChange24h().doubleValue()); //平均涨跌幅

                    if (conceptIndex != null && conceptIndex.getMaxPercentChange24hInfo() != null) {
                        CmcCurrencyInfo maxInfo = conceptIndex.getMaxPercentChange24hInfo();
                        if (maxInfo.getPercentChange24h() != null) {
                            double max = StringUtil.getDoubleTwo(Double.parseDouble(maxInfo.getPercentChange24h()));
                            vo.setStrongestCurrency(max + "");   //币种表现最强
                            vo.setStrongestSymbol(maxInfo.getSymbol());
                        } else {
                            vo.setStrongestCurrency("0");
                        }
                    }
                    if (vo.getChange() == null) vo.setChange(0.00);
                    conList.add(vo);
                }
            }
            LogTrace.info("热门概念hbase查询", "耗时", String.valueOf(System.currentTimeMillis() - jStart));

            //根据平均涨幅升降序排列
            Collections.sort(conList, new Comparator<ConceptQuotationVo>() {

                public int compare(ConceptQuotationVo o1, ConceptQuotationVo o2) {

                    if (o1.getChange() > o2.getChange()) {
                        return -1;
                    }
                    if (o1.getChange()!=null && o1.equals( o2.getChange() )) {
                        return 0;
                    }
                    return 1;
                }
            });
            conList = conList.subList(0, 8);
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(conList);
            return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("热门概念", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }

    /**
     * 平台币种
     *
     * @param T t
     * @return List<T>
     */
    public ApiResultVo conceptCurrency(CurrencyInfo currencyInfo) {
        ApiResultVo resultVo = new ApiResultVo();
        try {
            List<ApiConceptSymbolVo> symbolVoList = new ArrayList<ApiConceptSymbolVo>();
            List<CurrencyInfo> currencyInfoList = currencyInfoMapper.serchByCurrentId(currencyInfo);

            for(int i=0;i<currencyInfoList.size();i++){
                CurrencyInfo  currencyInfo1 = currencyInfoList.get( i );
                if(StringUtils.isNotBlank( currencyInfo1.getCmcId() )){
                    CurrencyQuotationResultVo currencyQuotationResultVo = immortalsService.getCurrencyByCmcId( currencyInfo1.getCmcId() );
                    ApiConceptSymbolVo apiConceptSymbolVo = new ApiConceptSymbolVo();
                    apiConceptSymbolVo.setRank( i+1 );
                    if(currencyQuotationResultVo!=null){
                        apiConceptSymbolVo.setUrl( currencyQuotationResultVo.getImageUrl() );
                        apiConceptSymbolVo.setSymbol( currencyQuotationResultVo.getSymbol() );
                        apiConceptSymbolVo.setMarketVolume( currencyQuotationResultVo.getMarketCapCny() );
                        apiConceptSymbolVo.setPrice( currencyQuotationResultVo.getPriceCny() );
                        apiConceptSymbolVo.setCirculatingSupply( currencyQuotationResultVo.getCirculatingSupply() );
                        apiConceptSymbolVo.setVolume24h( currencyQuotationResultVo.getVolume24h() );
                        apiConceptSymbolVo.setChange( currencyQuotationResultVo.getChange24h() );
                        apiConceptSymbolVo.setTurnover( currencyQuotationResultVo.getTurnover() );
                        apiConceptSymbolVo.setName( currencyQuotationResultVo.getName() );
                        apiConceptSymbolVo.setKLine7D( currencyQuotationResultVo.getKLine7D() );
                        apiConceptSymbolVo.setScore( currencyQuotationResultVo.getScore() );
                        apiConceptSymbolVo.setCmcId( currencyQuotationResultVo.getCmcId() );
                        apiConceptSymbolVo.setId( Integer.valueOf( currencyQuotationResultVo.getId() ) );
                        symbolVoList.add( apiConceptSymbolVo );
                    }
                }
            }
                if (symbolVoList.size() == 0) {
                    resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                    resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
                    resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                    return resultVo;
                }

                //根据流通市值排序
                if (currencyInfo.getMarketVolumeType() == 1) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getMarketVolume() > o2.getMarketVolume()) {
                                return -1;
                            }
                            if (o1.getMarketVolume() == o2.getMarketVolume()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }
                if (currencyInfo.getMarketVolumeType() == 2) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getMarketVolume() < o2.getMarketVolume()) {
                                return -1;
                            }
                            if (o1.getMarketVolume() == o2.getMarketVolume()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }

                //根据价格排序
                if (currencyInfo.getPriceType() == 1) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getPrice() > o2.getPrice()) {
                                return -1;
                            }
                            if (o1.getPrice() == o2.getPrice()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }
                if (currencyInfo.getPriceType() == 2) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getPrice() < o2.getPrice()) {
                                return -1;
                            }
                            if (o1.getPrice() == o2.getPrice()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }

                //根据流通数量排序
                if (currencyInfo.getCirculatingSupplyType() == 1) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getCirculatingSupply() > o2.getCirculatingSupply()) {
                                return -1;
                            }
                            if (o1.getCirculatingSupply() == o2.getCirculatingSupply()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }
                if (currencyInfo.getCirculatingSupplyType() == 2) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getCirculatingSupply() < o2.getCirculatingSupply()) {
                                return -1;
                            }
                            if (o1.getCirculatingSupply() == o2.getCirculatingSupply()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }

                //根据成交额排序
                if (currencyInfo.getVolume24hType() == 1) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getVolume24h() > o2.getVolume24h()) {
                                return -1;
                            }
                            if (o1.getVolume24h() == o2.getVolume24h()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }
                if (currencyInfo.getVolume24hType() == 2) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getVolume24h() < o2.getVolume24h()) {
                                return -1;
                            }
                            if (o1.getVolume24h() == o2.getVolume24h()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }

                //根据涨跌幅排序
                if (currencyInfo.getChangeType() == 1) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getChange() > o2.getChange()) {
                                return -1;
                            }
                            if (o1.getChange() == o2.getChange()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }
                if (currencyInfo.getChangeType() == 2) {
                    Collections.sort(symbolVoList, new Comparator<ApiConceptSymbolVo>() {
                        public int compare(ApiConceptSymbolVo o1, ApiConceptSymbolVo o2) {
                            if (o1.getChange() < o2.getChange()) {
                                return -1;
                            }
                            if (o1.getChange() == o2.getChange()) {
                                return 0;
                            }
                            return 1;
                        }
                    });
                }
            //判断每条数据是否已自选(如果用户已经登录)
            //List<CurrencyQuotationResultVo> resultSelf = (List<CurrencyQuotationResultVo>) result;
            if(StringUtils.isNotBlank(currencyInfo.getUserToken())){
                Integer user_id = shelSelectService.getRedisUserId(currencyInfo.getUserToken());
                if(null != user_id){
                    List<Integer> middleList = new ArrayList<>();
                    for(ApiConceptSymbolVo q:symbolVoList){
                        middleList.add(Integer.valueOf(q.getId()));
                    }
                    if(middleList.size() > 0){
                        Map<String,Object> params = new HashMap<>();
                        params.put("type",2);
                        params.put("uniqueAnnotationList",middleList);
                        params.put("user_id",user_id);
                        List<SelfSelected> selfList = selfSelectedMapper.getSelfSelectByMideleId(params);
                        if(selfList != null && selfList.size()>0){
                            Map<Integer,Object> selfMap = new HashMap<>();
                            for(SelfSelected selfSelected : selfList){
                                selfMap.put(selfSelected.getUniqueAnnotation(),selfSelected.getUniqueAnnotation());
                            }
                            for(ApiConceptSymbolVo q:symbolVoList){
                                if(Integer.valueOf(q.getId()) != null && selfMap.containsKey(Integer.valueOf(q.getId()))){
                                    q.setSelfSelectFlag(1);
                                }
                            }
                        }
                    }
                }
            }
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(symbolVoList);
                return resultVo;
        } catch (Exception e) {
            e.printStackTrace();
            LogTrace.error("平台币种", e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return resultVo;
        }
    }


    /**
     * 货币诊断-排行榜
     * @param T t
     * @return List<T>
     */
    public ApiResultVo monetarydiagnosisTop() {
        ApiResultVo resultVo=new ApiResultVo();

        Long jStart = System.currentTimeMillis();
        String curentcyHigh=redisServer.get(RedisKeysUtils.COIN_RANK);
        LogTrace.info("货币诊断-排行榜hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));
        CoinRank coinRank=JSON.parseObject(curentcyHigh, CoinRank.class);

        String scoreList=redisServer.get(RedisKeysUtils.DIAGNOSIS_SCORE_RANK);
        List<DiagnosisScore> diaList=JSON.parseArray(scoreList,DiagnosisScore.class);
        try {
            MoneyDiagnosisTopVo moneyDiagnosisTopVo=new MoneyDiagnosisTopVo();
            List<CmcCurrencyInfo> shizhiList=coinRank.getMarketCapRankList();
            List<CmcCurrencyInfo> zhangfuList=coinRank.getPercentChangeRankList();
            List<CmcCurrencyInfo> jiaoyiliangList=coinRank.getVolumeRankList();

            List<MgvVo> shiList=new ArrayList<>();
            List<MgvVo> zhangList=new ArrayList<>();
            List<MgvVo> jiaoList=new ArrayList<>();
            List<CurrScoreVo> scores=new ArrayList<>();
            for (int i=0;i<shizhiList.size();i++){
                CurrencyInfo info = redisCacheComponent.getCurrencyInfo(shizhiList.get(i).getId());
                MgvVo shizhi=new MgvVo();
                shizhi.setDiagnosisId(shizhiList.get(i).getId());
                shizhi.setRank(i+1+"");
                shizhi.setSymbols(shizhiList.get(i).getSymbol());
                shizhi.setMarketCap(shizhiList.get(i).getMarketCapCny());
                shizhi.setImageUrl( info.getImageUrl() );
                shiList.add(shizhi);
            }

            for (int i=0;i<zhangfuList.size();i++) {
                CurrencyInfo info = redisCacheComponent.getCurrencyInfo(zhangfuList.get(i).getId());
                MgvVo zhangfu=new MgvVo();
                zhangfu.setDiagnosisId(zhangfuList.get(i).getId());
                zhangfu.setRank(i+1+"");
                zhangfu.setSymbols(zhangfuList.get(i).getSymbol());
                zhangfu.setChange(zhangfuList.get(i).getPercentChange24h());
                zhangfu.setImageUrl( info.getImageUrl() );

                //最新价格
                ExchangeTransactionpairMiddle exchangeTransactionpairMiddle=new ExchangeTransactionpairMiddle();
                exchangeTransactionpairMiddle.setTransactionName(zhangfuList.get(i).getId());
                List<ExchangeTransactionpairMiddle> exchangeTransactionpairMiddleList = exchangeTransactionpairMiddleMapper.getTransactionPairByCurrencyInfo( exchangeTransactionpairMiddle );
                if(exchangeTransactionpairMiddleList.size()>0){
                    exchangeTransactionpairMiddle = exchangeTransactionpairMiddleList.get( 0 );
                    Long nowTImeres = DateUtils.getCurrentDataLong();
            nowTImeres=nowTImeres-86400000;
                    LocalDateTime timeres = DateUtils.getDateTimeOfTimestamp( nowTImeres );
                    String redisPriceDate = DateUtils.localDateTimeFormatString(timeres,DateUtils.format_ymds);
                    String Rediskey = RedisKeysUtils.API_SERVICE_K_ACTION_ALL_DATA_PRICE + "@" + exchangeTransactionpairMiddle.getExchangeId()+ "@" + exchangeTransactionpairMiddle.getTransactionName();
                    String API_SERVICE_K_ACTION_CHANGE_PRICE = redisServer.get( Rediskey );
                    if(API_SERVICE_K_ACTION_CHANGE_PRICE!=null){
                        KActionTotalPo rActionTotalPo = JSON.parseObject( API_SERVICE_K_ACTION_CHANGE_PRICE,KActionTotalPo.class );
                        zhangfu.setPrice( Double.parseDouble( rActionTotalPo.getOpenPriceCny()) );
                    }
                }
                zhangList.add(zhangfu);
            }

            for (int i=0;i<jiaoyiliangList.size();i++){
                CurrencyInfo info = redisCacheComponent.getCurrencyInfo(jiaoyiliangList.get(i).getId());
                MgvVo jiaoyi=new MgvVo();
                jiaoyi.setDiagnosisId(jiaoyiliangList.get(i).getId());
                jiaoyi.setRank(i+1+"");
                jiaoyi.setSymbols(jiaoyiliangList.get(i).getSymbol());
                jiaoyi.setVolume(jiaoyiliangList.get(i).getVolume24hCny());
                jiaoyi.setImageUrl( info.getImageUrl() );
                jiaoList.add(jiaoyi);
            }

            for (int i=0;i<diaList.size();i++){
                CurrScoreVo score=new CurrScoreVo();
                score.setScore(diaList.get(i).getDiagnosisScore().setScale(1, BigDecimal.ROUND_DOWN).toString());
                score.setRank(i+1+"");
                score.setCmcId( diaList.get(i).getId() );
                CurrencyInfo info = redisCacheComponent.getCurrencyInfo(diaList.get(i).getId());
                score.setSymbols(info.getSymbol());
                score.setImageUrl( info.getImageUrl() );
                scores.add(score);
            }

            moneyDiagnosisTopVo.setMarketCaps(shiList);
            moneyDiagnosisTopVo.setGains(zhangList);
            moneyDiagnosisTopVo.setVolumes(jiaoList);
            moneyDiagnosisTopVo.setScores(scores);

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(moneyDiagnosisTopVo);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("货币诊断-排行榜",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     * 货币诊断排名前5
     * @param T t
     * @return List<T>
     */
    public ApiResultVo monetarydiagnosisTop5() {
        ApiResultVo resultVo=new ApiResultVo();
        try {
            Date date =new Date();
            SimpleDateFormat sdf =new SimpleDateFormat("HH:mm:ss");//只有时分秒
            String time=sdf.format(date);

            String curentcyHigh=redisServer.get(RedisKeysUtils.COIN_RANK);
            CoinRank coinRank=JSON.parseObject(curentcyHigh, CoinRank.class);

            List<MoneyDiagnosisTop5Vo> hotList=new ArrayList<>(  );
                for (int i = 0; i < (coinRank.getMarketCapRankList().size()>5?5:coinRank.getMarketCapRankList().size()); i++) {
                    CmcCurrencyInfo cyInfo = coinRank.getMarketCapRankList().get( i );
                    ApiCurrencyDiagnosisScoreVo vo=new ApiCurrencyDiagnosisScoreVo();
                    String redisDate = redisServer.get(RedisKeysUtils.DIAGNOSIS_CURRENCY_SCORE_INFO+cyInfo.getId());
                    if(org.apache.commons.lang3.StringUtils.isNotBlank(redisDate)){
                        LogTrace.info("货币诊断排名前5", "数据来源:","redis-"+cyInfo.getId());
                        vo = JSON.parseObject(redisDate,ApiCurrencyDiagnosisScoreVo.class);
                    }else {
                        LogTrace.info("货币诊断排名前5", "数据来源:","hbase-"+cyInfo.getId());
                        vo=MakeCurrencyDiagnosisScore(cyInfo.getId());
                    }
                    if(vo!=null){
                        CurrencyInfo info = redisCacheComponent.getCurrencyInfo(cyInfo.getId());
                        List<Integer> assess=new ArrayList<>(  );
                        MoneyDiagnosisTop5Vo topVo = new MoneyDiagnosisTop5Vo();
                        topVo.setScore( vo.getScore() );
                        topVo.setWinPercent( vo.getWinPercent() );
                        topVo.setPopularityIndex( vo.getPopularityIndex() );
                        topVo.setCurrencyLiquidity( vo.getCurrencyLiquidity() );
                        topVo.setEnergyChange( vo.getEnergyChange() );
                        topVo.setMarketHeat( vo.getMarketHeat() );
                        topVo.setSymbol( cyInfo.getSymbol() );
                        topVo.setDiagnosisId( cyInfo.getId());
                        topVo.setImageUrl( info.getImageUrl() );
                        assess.add(Integer.parseInt( vo.getIndicator().get( 2 ).toString() )); //流动性
                        assess.add(  Integer.parseInt( vo.getIndicator().get( 3 ).toString() ) ); //量能变化
                        assess.add(  Integer.parseInt( vo.getIndicator().get( 0 ).toString() ) ); //市场热度
                        assess.add(  Integer.parseInt( vo.getIndicator().get( 1 ).toString() ) ); //人气意愿指标
                        topVo.setAssess(assess);
                        hotList.add( topVo );
                    }
                }

            resultVo.setCode( ApiResultCodeUtils.BASE_SUCCESS.getCode() );
            resultVo.setMessage( ApiResultCodeUtils.BASE_SUCCESS.getMsg() );
            resultVo.setTradeId( LogTrace.getTrace().getTraceId() );
            resultVo.setData( hotList);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("货币诊断排名前5",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }


    /**
     * 组装货币诊断得分到redis中
     * @param vo
     * @param cmc_id
     * @throws Exception
     */
    public ApiCurrencyDiagnosisScoreVo MakeCurrencyDiagnosisScore(String cmc_id) throws Exception{
        ApiCurrencyDiagnosisScoreVo vo=new ApiCurrencyDiagnosisScoreVo();
        String grailStr = null;
        //获取当前小时
        Long hstartt = System.currentTimeMillis();
        String rowKey = "";
        int day =0;
        while (org.apache.commons.lang3.StringUtils.isBlank(grailStr)){//循环获取，指导获取到数据
            rowKey = DateUtils.getNextDayDateYMD(day);
            grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_TABLE_NAME
                    , HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_TABLE_FAMILY
                    , HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_QUALIFIER
                    , cmc_id+"@"+rowKey);//DateUtils.getCurrentDateString()
            day --;
            if(org.apache.commons.lang3.StringUtils.isNotBlank(grailStr)||day<-1){
                break;
            }
        }
        LogTrace.info("hbase数据查询",rowKey+"是否存在数据"+cmc_id, org.apache.commons.lang3.StringUtils.isBlank(grailStr)?"无数据":"有数据");
        if(org.apache.commons.lang3.StringUtils.isBlank(grailStr)){
            return null;
        }
        //数据库查询模型symbol
        CurrencyInfo queryInfo = new CurrencyInfo();
        queryInfo.setCmcId(cmc_id);
        Long dstart = System.currentTimeMillis();
        // CurrencyInfo infoList  =  currencyInfoMapper.selectByEntity(queryInfo);
        CurrencyInfo info = redisCacheComponent.getCurrencyInfo(cmc_id);
        LogTrace.info("量化评估-获取诊断得分-redis查询","耗时",String.valueOf(System.currentTimeMillis()-dstart));
        //获取指定货币量能变化  DiagnosisQuantumEnergy
        Map<String,Object> diagnosisMap = JSON.parseObject(grailStr);
        String dataDiagnosi = "";
        int maxHour = 0;
        //获取最后数据
        for(Map.Entry<String,Object> maxMap : diagnosisMap.entrySet()){
            int tempHour = Integer.valueOf(maxMap.getKey());
            if(tempHour >= maxHour){
                maxHour = tempHour;
                //dataDiagnosi = JSON.toJSONString(diagnosisMap.get(String.valueOf(hourStr)));
                dataDiagnosi = JSON.toJSONString(maxMap.getValue());
            }
        }
        LogTrace.info("量化评估-获取诊断得分-时间",String.valueOf(maxHour), org.apache.commons.lang3.StringUtils.isBlank(dataDiagnosi)?"无数据":"有数据");
        List<DiagnosisScore> diagnosisScoreList = JSON.parseArray(dataDiagnosi,DiagnosisScore.class);
        if(diagnosisScoreList == null || diagnosisScoreList.size() == 0) return null;
        DiagnosisScore diagnosisScore = diagnosisScoreList.get(diagnosisScoreList.size()-1);
        vo.setDiagnosisId(String.valueOf(1));
        vo.setScore(diagnosisScore.getDiagnosisScore().setScale(1, BigDecimal.ROUND_DOWN).toString());
        //记录内容是否为空
        LogTrace.info("量化评估-获取诊断得分-量能、流动、市场、ar人气数据","数据",JSON.toJSONString(diagnosisScore));
        //评语
        vo.setEnergyChange(diagnosisScore.getQuantumEnergyComment()!=null?diagnosisScore.getQuantumEnergyComment():"");
        vo.setCurrencyLiquidity(diagnosisScore.getLiquidityComment()!=null?diagnosisScore.getLiquidityComment():"");
        vo.setPopularityIndex(diagnosisScore.getPopularityIndicatorComment()!=null?diagnosisScore.getPopularityIndicatorComment():"");
        vo.setMarketHeat(diagnosisScore.getTrendsInfoResult()!=null && diagnosisScore.getTrendsInfoResult()!=null?diagnosisScore.getTrendsInfoResult():""); //市场热度评语
        vo.setWinPercent(diagnosisScore.getDefect()!=null?diagnosisScore.getDefect().multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_DOWN).toString():"0");  //打败
        //雷达图数据插入顺序 市场热度，人气指标，货币流动性，量能变化
        List<String> indicator = new ArrayList<>();
        indicator.add(diagnosisScore.getTrendsInfoScore()!=null&&diagnosisScore.getTrendsInfoScore()!=null?diagnosisScore.getTrendsInfoScore().toString():"0");//市场待取
        indicator.add(diagnosisScore.getPopularityIndicatorScore()!=null?diagnosisScore.getPopularityIndicatorScore().toString():"0");//ar人气指标
        indicator.add(diagnosisScore.getLiquidityScore()!=null?diagnosisScore.getLiquidityScore().toString():"0"); //货币流动性
        indicator.add(diagnosisScore.getQuantumEnergyScore()!=null?diagnosisScore.getQuantumEnergyScore().toString():"0");//量能变化
        vo.setIndicator(indicator);
        if(info!=null){
            vo.setSymbol(info.getSymbol());//插入模型
            vo.setCoinNameCn(info.getCoinNameCn());
            vo.setImageUrl( info.getImageUrl() );
        }

        redisServer.set(RedisKeysUtils.DIAGNOSIS_CURRENCY_SCORE_INFO+cmc_id,JSON.toJSONString(vo),300L);
        return  vo;
    }
    /**
     * 涨跌统计
     * @param T t
     * @return List<T>
     */
    public ApiResultVo fallStatistics() {
        ApiResultVo resultVo=new ApiResultVo();
        CurrentcyHighOrLow curentcyHigh=null;

        try {
            Long jStart = System.currentTimeMillis();
            String fallStr=redisServer.get(RedisKeysUtils.TIR_CHANGE_STATISTICS);
            LogTrace.info("涨跌统计redis查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));
            LogTrace.info("涨跌统计", "fallStatistics涨跌统计接口redis返回:",null);
            if (fallStr!=null){
                curentcyHigh=JSON.parseObject(fallStr, CurrentcyHighOrLow.class);
            }

            if (fallStr==null){
                String data = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.DAILY_CHANGE_STATISTICS_INFO_TABLE_NAME
                        , HbaseTableUtils.DAILY_CHANGE_STATISTICS_INFO_TABLE_FAMILY
                        , HbaseTableUtils.DAILY_CHANGE_STATISTICS_INFO_TABLE_QUALIFIER
                        , DateUtils.getCurrentDateString());
                LogTrace.info("涨跌统计", "fallStatistics涨跌统计接口hbase:",null);

                JSONObject json = JSON.parseObject( data );
                if (json!=null){
                    Set<String> setString=json.keySet();
                    Iterator it1 = setString.iterator();
                    String lastKey=null;
                    while(it1.hasNext()){
                        lastKey=it1.next()+"";
                    }
                    JSONArray advice = (JSONArray) json.getJSONArray( lastKey );
                    if (advice.size()>0){
                        curentcyHigh=JSON.parseObject(advice.get( 0 ).toString(), CurrentcyHighOrLow.class);
                    }
                }
            }

            GraliIntensity graliIntensity=new GraliIntensity();
            graliIntensity.setInterpretationId(1);
            graliIntensity.setInterpretation("涨跌统计");
            graliIntensity.setTime(curentcyHigh.getDateTime());
            graliIntensity.setScore(curentcyHigh.getScore());
            graliIntensity.setResult(curentcyHigh.getEvaluate());
            graliIntensity.setCurrencys(curentcyHigh.getAllCount());
            graliIntensity.setAllCount(curentcyHigh.getAllCount()+"");
            graliIntensity.setUpCount( curentcyHigh.getUpCount()+"" );
            graliIntensity.setDownCount( curentcyHigh.getDownCount()+"" );

            ChartVo vo=new ChartVo();
            List<String> xList=new ArrayList<String>();
            xList.add("-10%以下");
            xList.add("-10%至-6%");
            xList.add("-6%至-4%");
            xList.add("-4%至-2%");
            xList.add("-2%至0%");
            xList.add("0%至2%");
            xList.add("2%至4%");
            xList.add("4%至6%");
            xList.add("6%至10%");
            xList.add("10%以上");
            vo.setX(xList);
            List<Integer> yList=new ArrayList<Integer>();
            yList.add(curentcyHigh.getF10());
            yList.add(curentcyHigh.getF10Tof6());
            yList.add(curentcyHigh.getF6Tof2());
            yList.add(curentcyHigh.getF2To0());
            yList.add(curentcyHigh.getZ0Toz2());
            yList.add(curentcyHigh.getZ2Toz4());
            yList.add(curentcyHigh.getZ4Toz6());
            yList.add(curentcyHigh.getZ6Toz8());
            yList.add(curentcyHigh.getZ8Toz10());
            yList.add(curentcyHigh.getZ10());

            vo.setY(yList);

            graliIntensity.setChart(vo);
            graliIntensity.setExplanation("主要货币中，过去24小时，价格上涨的货币数量越多，整个行情就越高涨，反之，下跌的货币数量越多，整个行情就越低迷。");

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(graliIntensity);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("涨跌统计",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     行业货币分类 暂时不使用
     * @param T t
     * @return List<T>
     */
    public ApiResultVo bottomtechnology1() {
        ApiResultVo resultVo=new ApiResultVo();
        List<CurrInHangVo> hangVoList=new ArrayList<>();

        try {
            List<CurrencyInfo> list=null;
            CurrencyIndustryCategory currencyIndustry=new CurrencyIndustryCategory();
            currencyIndustry.setParentId(0);
            currencyIndustry.setEnableFlag(true);
            currencyIndustry.setDeleteFlag(false);
            List<CurrencyIndustryCategory> currList=currencyIndustryCategoryMapper.selectByEntityList(currencyIndustry);
            List CInList=new ArrayList();
            Map map=new HashMap();

            Date date =new Date();
            SimpleDateFormat sdf =new SimpleDateFormat("HH:mm:ss");//只有时分秒
            String time=sdf.format(date);
            String hour=time.substring(0,2);
            Long jStart = System.currentTimeMillis();
            for (int k=0;k<currList.size();k++){
                CurrInHangVo hangVo=new CurrInHangVo();

                CurrencyIndustryCategory currencyIn = currList.get(k);
                currencyIndustry.setParentId(currencyIn.getId());
                currencyIndustry.setEnableFlag(true);
                currencyIndustry.setDeleteFlag(false);
                List<CurrencyIndustryCategory> currList2=currencyIndustryCategoryMapper.selectByEntityList(currencyIndustry);

                List<CurrInVo> voList=new ArrayList<>();
                for (int v=0;v<currList2.size();v++){
                    List<BottomTechnologyVo> logvoList=new ArrayList<BottomTechnologyVo>();
                    CurrInVo vo=new CurrInVo();
                    //根据行业id查询货币
                    CurrencyInfo infoo=new CurrencyInfo();
                    infoo.setId(currList2.get(v).getId());
                    list = currencyInfoMapper.serchByCurrenByIncurrId(infoo);
                    //根据货币id进行匹配
                    for (int i=0;i<list.size();i++){
                        CurrencyInfo info=list.get(i);
                        CurrencyGainPriceRedisBo redisRo=redisCacheComponent.getCurrecyGainPriceRedisBo( info.getCmcId() );
                        if (redisRo!=null) {
                            BottomTechnologyVo logvo=new BottomTechnologyVo();
                            logvo.setImageUrl(info.getImageUrl());
                            logvo.setCoinNameEn(info.getCoinNameEn());
                            logvo.setCoinNameCh(info.getCoinNameCn());
                            if(redisRo.getPrice()!=null)logvo.setPrice( StringUtil.getPriceTwo(redisRo.getPrice()));
                            if(redisRo.getGains()!=null)logvo.setChange(Double.parseDouble( redisRo.getGains()));
                            logvoList.add(logvo);
                        }else {
                            String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.DAILY_CURRENCY_INFOR_TABLE_NAME
                                    , HbaseTableUtils.DAILY_CURRENCY_INFOR_TABLE_FAMILY
                                    , HbaseTableUtils.DAILY_CURRENCY_INFOR_TABLE_QUALIFIER
                                    , info.getCmcId() + "@" + DateUtils.getCurrentDateString()
                            );

                            if (grailStr != null) {
                                JSONObject json = JSON.parseObject( grailStr );
                                JSONArray advice = (JSONArray) json.getJSONArray( hour );
                                if (advice == null) {
                                    //如果数据是空，就取上个小时的数据
                                    advice = (JSONArray) json.getJSONArray( StringUtil.getLastHour() );
                                }
                                if (advice != null) {
                                    JSONObject obj = (JSONObject) advice.get( advice.size() - 1 );
                                    if (info.getCmcId().equals( obj.get( "id" ) )) {
                                        BottomTechnologyVo logvo = new BottomTechnologyVo();
                                        logvo.setImageUrl( info.getImageUrl() );
                                        logvo.setCoinNameEn( info.getCoinNameEn() );
                                        logvo.setCoinNameCh( info.getCoinNameCn() );
                                        if (obj.containsKey( "priceCny" ))
                                            logvo.setPrice( StringUtil.getPriceTwo(Double.parseDouble(obj.get( "priceCny" ).toString())));
                                        if (obj.containsKey( "percentChange24h" ))
                                            logvo.setChange( Double.parseDouble( obj.get( "percentChange24h" ).toString() ) );
                                        logvoList.add( logvo );
                                    }
                                }
                            }
                        }
                    }

                    vo.setName(currList2.get(v).getIndustryName());
                    vo.setLogvoList(logvoList);
                    voList.add(vo);
                }

                hangVo=new CurrInHangVo();
                hangVo.setName(currencyIn.getIndustryName());
                hangVo.setCurrInVoList(voList);
                hangVoList.add(hangVo);
            }

            LogTrace.info("行业货币分类hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(hangVoList);

            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("行业货币分类",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }

    }
    public ApiResultVo bottomtechnology() {
        ApiResultVo resultVo=new ApiResultVo();
        List<CurrInHangVo> hangVoList=new ArrayList<>();

        try {
            List<CurrencyInfo> list=null;
            CurrencyIndustryCategory currencyIndustry=new CurrencyIndustryCategory();
            currencyIndustry.setParentId(0);
            currencyIndustry.setEnableFlag(true);
            currencyIndustry.setDeleteFlag(false);
            List<CurrencyIndustryCategory> currList=currencyIndustryCategoryMapper.selectByEntityList(currencyIndustry);
            List CInList=new ArrayList();
            Map map=new HashMap();

            Date date =new Date();
            SimpleDateFormat sdf =new SimpleDateFormat("HH:mm:ss");//只有时分秒
            String time=sdf.format(date);
            String hour=time.substring(0,2);
            Long jStart = System.currentTimeMillis();
            for (int k=0;k<currList.size();k++){
                CurrInHangVo hangVo=new CurrInHangVo();
                List<CurrInVo> voList=new ArrayList<>();
                List<BottomTechnologyVo> logvoList=new ArrayList<BottomTechnologyVo>();
                CurrInVo vo=new CurrInVo();
                //根据行业id查询货币
                CurrencyInfo infoo=new CurrencyInfo();
                infoo.setId(currList.get(k).getId());
                list = currencyInfoMapper.serchByCurrenByIncurrId(infoo);
                //根据货币id进行匹配
                for (int i=0;i<list.size();i++){
                    CurrencyInfo info=list.get(i);
                    LogTrace.info("行业货币分类hbase查询","cmcId:",info.getCmcId());

                    CurrencyGainPriceRedisBo redisRo=redisCacheComponent.getCurrecyGainPriceRedisBo( info.getCmcId() );
                    if (redisRo!=null) {
                        BottomTechnologyVo logvo=new BottomTechnologyVo();
                        logvo.setImageUrl(info.getImageUrl());
                        logvo.setCoinNameEn(info.getCoinNameEn());
                        logvo.setCoinNameCh(info.getCoinNameCn());
                        if(redisRo.getPrice()!=null)logvo.setPrice( StringUtil.getPriceTwo(redisRo.getPrice()));
                        if(redisRo.getGains()!=null)logvo.setChange(Double.parseDouble( redisRo.getGains()));
                        logvoList.add(logvo);
                    }else {
                        String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.DAILY_CURRENCY_INFOR_TABLE_NAME
                                , HbaseTableUtils.DAILY_CURRENCY_INFOR_TABLE_FAMILY
                                , HbaseTableUtils.DAILY_CURRENCY_INFOR_TABLE_QUALIFIER
                                , info.getCmcId() + "@" + DateUtils.getCurrentDateString()
                        );

                        if (grailStr != null) {
                            JSONObject json = JSON.parseObject( grailStr );
                            JSONArray advice = (JSONArray) json.getJSONArray( hour );
                            if (advice == null) {
                                //如果数据是空，就取上个小时的数据
                                advice = (JSONArray) json.getJSONArray( StringUtil.getLastHour() );
                            }
                            if (advice != null) {
                                JSONObject obj = (JSONObject) advice.get( advice.size() - 1 );
                                if (info.getCmcId().equals( obj.get( "id" ) )) {
                                    BottomTechnologyVo logvo = new BottomTechnologyVo();
                                    logvo.setImageUrl( info.getImageUrl() );
                                    logvo.setCoinNameEn( info.getCoinNameEn() );
                                    logvo.setCoinNameCh( info.getCoinNameCn() );
                                    if (obj.containsKey( "priceCny" ))
                                        logvo.setPrice( StringUtil.getPriceTwo(Double.parseDouble(obj.get( "priceCny" ).toString())));
                                    if (obj.containsKey( "percentChange24h" ))
                                        logvo.setChange( Double.parseDouble( obj.get( "percentChange24h" ).toString() ) );
                                    logvoList.add( logvo );
                                }
                            }
                        }
                    }
                }
                vo.setName("");
                vo.setLogvoList(logvoList);
                voList.add(vo);
                hangVo=new CurrInHangVo();
                hangVo.setName(currList.get(k).getIndustryName());
                hangVo.setCurrInVoList(voList);
                hangVoList.add(hangVo);

            }

            LogTrace.info("行业货币分类hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(hangVoList);
            redisServer.set( RedisKeysUtils.DIAGNOSIS_Top5_INDEX,JSON.toJSONString( hangVoList ),300L);

            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("行业货币分类",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }

    }


    /**
     *
     行业货币分类(递归)
     * @param T t
     * @return List<T>
     */
    public ApiResultVo bottomtechnology2() {
        ApiResultVo resultVo=new ApiResultVo();
        List<CurrInHangMenu> hangVoList=new ArrayList<>();

        String CURRENCY_CLASSIFICATION=redisServer.get( RedisKeysUtils.CURRENCY_CLASSIFICATION );
        if (CURRENCY_CLASSIFICATION!=null){
            hangVoList = JSON.parseArray( CURRENCY_CLASSIFICATION, CurrInHangMenu.class );
            if (hangVoList.size()>0){
                LogTrace.info("行业货币分类","redis",null);
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(hangVoList);
                return resultVo;
            }
        }

        try {
            CurrencyIndustryCategory currencyIndustry=new CurrencyIndustryCategory();
            currencyIndustry.setEnableFlag(true);
            currencyIndustry.setDeleteFlag(false);
            List<CurrencyIndustryCategory> currList=currencyIndustryCategoryMapper.selectByEntityList(currencyIndustry);
            for (int j=0;j<currList.size();j++){
                if (currList.get( j ).getParentId()==0){
                    CurrInHangMenu hVO=new CurrInHangMenu();
                    hVO.setId( currList.get( j ).getId() );
                    hVO.setName(currList.get( j ).getIndustryName());
                    hVO.setParentId( currList.get( j ).getParentId() );
                    List<BottomTechnologyVo> logvoList = getCurrency(currList.get( j ).getId());
                    hVO.setLogvoList(logvoList);
                    hangVoList.add( hVO );
                }
            }

            for (CurrInHangMenu vo:hangVoList){
                vo.setCurrInHangMenuList( getChild(  vo.getId() ,currList ) );
            }

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());

            redisServer.set( RedisKeysUtils.CURRENCY_CLASSIFICATION,JSON.toJSONString( hangVoList ),300L);
            resultVo.setData(hangVoList);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("行业货币分类",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    private List<CurrInHangMenu> getChild(Integer id,List<CurrencyIndustryCategory> rootMenu) throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {

        List<CurrInHangMenu> childList = new ArrayList<>();

        for(CurrencyIndustryCategory category:rootMenu){
            if (id != null && id.equals(category.getParentId())){
                CurrInHangMenu vo=new CurrInHangMenu();
                vo.setId( category.getId());
                vo.setName( category.getIndustryName() );
                vo.setParentId( category.getParentId() );

                //根据行业id查询货币
                List<BottomTechnologyVo> logvoList = getCurrency(category.getId());
                vo.setLogvoList( logvoList );
                childList.add( vo );
            }
        }
        for (CurrInHangMenu menu:childList){
            menu.setCurrInHangMenuList(getChild( menu.getId(),rootMenu) );
        }

        if (childList.size() == 0) {
            return null;
        }
        return  childList;
    }

    private  List<BottomTechnologyVo> getCurrency(int id) throws HbaseCloseExcetion, IOException, HbaseGetTableExcetion, HbaseConnectionExcetion {
        //根据行业id查询货币
        CurrencyInfo infoo=new CurrencyInfo();
        infoo.setId(id);
        List<CurrencyInfo> list=currencyInfoMapper.serchByCurrenByIncurrId(infoo);
        List<BottomTechnologyVo> logvoList=new ArrayList<BottomTechnologyVo>();
        for (int i=0;i<list.size();i++) {
            CurrencyInfo info = list.get( i );
            LogTrace.info( "行业货币分类", "cmcId:", info.getCmcId() );

            String redisCacheKey = RedisKeysUtils.CURRENCY_MARKET + info.getCmcId();

            String result = redisServer.get( redisCacheKey );
            BottomTechnologyVo logvo = new BottomTechnologyVo();
            if (result != null) {
                LogTrace.info( "getCurrencyByCmcId", "resultKeyRedis", redisCacheKey );
                CurrencyQuotationResultVo currencyQuotationResultVo = JSON.parseObject( result, CurrencyQuotationResultVo.class );
                logvo.setImageUrl( currencyQuotationResultVo.getImageUrl() );
                if (info.getImageUrl() != null) {
                    if (info.getImageUrl().contains( "http" )) {
                        logvo.setImageUrl( info.getImageUrl() );
                    } else {
                        logvo.setImageUrl( ossTool.getOSSUrl( info.getImageUrl() ) );
                    }
                }
                logvo.setCoinNameEn( info.getCoinNameEn() );
                logvo.setCoinNameCh( info.getCoinNameCn() );
                logvo.setCmcId( info.getCmcId() );
                if (currencyQuotationResultVo.getPriceCny() != null)
                    logvo.setPrice( StringUtil.getPriceTwo( currencyQuotationResultVo.getPriceCny() ) );
                if (currencyQuotationResultVo.getChange24h() != null)
                    logvo.setChange( currencyQuotationResultVo.getChange24h() );
                logvoList.add( logvo );
            }
        }
        return logvoList;
    }
    /**
     *
     平台币概念指数
     * @param T t
     * @return List<T>
     */
    public ApiResultVo bottomteZhi(ConceptCategory conceptCategory) {
        ApiResultVo resultVo=new ApiResultVo();

        String BOTTOMTEZHI_INDEX=redisServer.get( RedisKeysUtils.BOTTOMTEZHI_INDEX+conceptCategory.getId() );

        if (StringUtils.isNotBlank( BOTTOMTEZHI_INDEX )){
            JSONArray json = JSON.parseArray( BOTTOMTEZHI_INDEX );

            List<GaiNianZhiShuVo> hotList = JSON.parseArray( json.toString(), GaiNianZhiShuVo.class );
            if (hotList.size()>0){
                LogTrace.info("平台币概念指数","redis",null);
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(hotList);
                return resultVo;
            }
        }

        Long jStart = System.currentTimeMillis();
        try {
            String rowkey = conceptCategory.getId()+"@"+DateUtils.getCurrentDateString();
            String grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.CONCEPTUAL_QUOTES_TABLE_NAME
                    , HbaseTableUtils.CONCEPTUAL_QUOTES_TABLE_NAME_FAMILY
                    , HbaseTableUtils.CONCEPTUAL_QUOTES_TABLE_NAME_QUALIFIER
                    , rowkey
            );
            LogTrace.info("平台币概念指数hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart+":"+rowkey));
            JSONObject json = JSON.parseObject(grailStr);

            List list=new ArrayList();
            List<String> x=new ArrayList<>();

            GaiNianZhiShuVo vo=new GaiNianZhiShuVo();
            List<GaiNianYVo> voList=new ArrayList<>();
            for (int i=0;i<24;i++){
                JSONArray advice =null;
                if (json!=null) {
                    advice = (JSONArray) json.getJSONArray( i+"" );
                }
                if (advice!=null) {
                    for(int j=0;j<advice.size();j++){
                        JSONObject obj = (JSONObject) advice.get(j);
                        GaiNianYVo gaiNianYVo=new GaiNianYVo();
                        if (obj.containsKey("createTime")) {
                            long timeStamp = Long.parseLong(obj.get("createTime").toString());  //获取当前时间戳,也可以是你自已给的一个随机的或是别人给你的时间戳(一定是long型的数据)
                            x.add(obj.get("createTime").toString());
                            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//这个是你要转成后的时间的格式
                            String sd2 = sdf2.format(new Date(Long.parseLong(String.valueOf(timeStamp))));   // 时间戳转换成时间
                            vo.setDate(sd2);
                        }
                        if (obj.containsKey("conceptIndex")) gaiNianYVo.setValue(obj.get("conceptIndex").toString());
                        if (obj.containsKey("avgPercentChange24h")) gaiNianYVo.setChange(obj.get("avgPercentChange24h").toString());
                        voList.add(gaiNianYVo);
                    }
                }
            }
            vo.setX(x);
            vo.setY(voList);
            list.add(vo);

            if (list.size()==0){
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                return resultVo;
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(list);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("平台币概念指数",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }

    }

    /**
     *
     货币搜索
     * @param T t
     * @return List<T>
     */
    public ApiResultVo currencySea(CurrencyInfo currencyInfo){
        ApiResultVo resultVo=new ApiResultVo();

        try {
            //货币
            currencySeaVo currencySeaVo=new currencySeaVo();
            currencyInfo.setCurrencyDiagnosisFlag( true );
            List<CurrencyInfo> CurrencyInfoList=currencyInfoMapper.getCurrencyList(currencyInfo);
           if(CurrencyInfoList.size()>0){
               currencySeaVo.setCurrencyInfolist( CurrencyInfoList );
           }
           //查询交易对和交易所信息
            ExchangeTransactionpairMiddle query = new ExchangeTransactionpairMiddle();
           query.setTransactionName(currencyInfo.getCoinNameCn());
            List<ExchangeTransactionpair> middleList = exchangeTransactionpairMiddleMapper.selectByEntityListOfKLine(query);
            if(middleList != null && middleList.size() >0){
                currencySeaVo.setExchangeTransactionpairsList(middleList);
            }
           //交易对
            TransactionPair transactionPair=new TransactionPair();
            transactionPair.setSymbol( currencyInfo.getCoinNameCn() );
            List<TransactionPair> transactionPairList = transactionPairMapper.getCurrencySea( transactionPair );
            if(transactionPairList.size()>0){
                currencySeaVo.setTransactionPairList( transactionPairList );
            }

            //交易所
            ExchangeInfo exchangeInfo =new ExchangeInfo();
            exchangeInfo.setExchangeName( currencyInfo.getCoinNameCn() );
            exchangeInfo.setShelfFlag( true );
            exchangeInfo.setEnableFlag( true );
            exchangeInfo.setDeleteFlag( false );
            List<ExchangeInfo> exchangeInfoList = exchangeInfoDao.getCurrencySea( exchangeInfo );
            if(exchangeInfoList.size()>0){
                currencySeaVo.setExchangeInfoList( exchangeInfoList );
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(currencySeaVo);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("货币搜索",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     * 添加自选-交易对搜索
     * @param apiCurrencyInfoVo
     * @return
     */
    public ApiResultVo<List<ApiTransactionPairSearchVo>> addSelfSelectPairSea(ApiCurrencyInfoVo apiCurrencyInfoVo) {
        ApiResultVo<List<ApiTransactionPairSearchVo>> resultVo=new ApiResultVo();
        try {
            //货币
           // currencySeaVo currencySeaVo=new currencySeaVo();
            List<ApiTransactionPairSearchVo> resultList = new ArrayList<>();
            Map<String,List<ExchangeTransactionpair>> resultMap = new HashMap<>();
            Integer user_id = null;
            if(StringUtils.isNotBlank(apiCurrencyInfoVo.getUserToken())){
                user_id = shelSelectService.getRedisUserId(apiCurrencyInfoVo.getUserToken());
            }
            LogTrace.infoKvs("添加自选-交易对搜索","user_id",String.valueOf(user_id));
            //从redis中获取货币信息
            List<CurrencyInfo>  allCurrencyInfo = redisCacheComponent.getCurrencyList();
            Map<String,CurrencyInfo> currencyInfoMap = new HashMap<>();
            if(allCurrencyInfo != null && allCurrencyInfo.size() > 0){
                for(CurrencyInfo currencyInfo:allCurrencyInfo){
                    currencyInfoMap.put(currencyInfo.getSymbol(),currencyInfo);
                }
            }
            //查询交易对和交易所信息
            ExchangeTransactionpairMiddle query = new ExchangeTransactionpairMiddle();
            query.setTransactionName(apiCurrencyInfoVo.getCoinNameCn());
            query.setUser_id(user_id);
            List<ExchangeTransactionpair> middleList = exchangeTransactionpairMiddleMapper.selectByEntityListOfKLine(query);
            if(middleList != null && middleList.size() >0){
                for(ExchangeTransactionpair exchangeTransactionpair : middleList){
                    if(exchangeTransactionpair.getSelfSelectFlag() != null){
                        exchangeTransactionpair.setSelfSelectFlag(1);
                    }else{
                        exchangeTransactionpair.setSelfSelectFlag(2);
                    }
                    //加入货币和图片地址
                    if(StringUtils.isNotBlank(exchangeTransactionpair.getTransactionName())){
                        String[] pair = exchangeTransactionpair.getTransactionName().split("/");
                        String symbol = pair[0];
                        CurrencyInfo currencyInfo = currencyInfoMap.get(symbol);
                        if(currencyInfo != null){
                            exchangeTransactionpair.setImageUrl(StringUtils.isNotBlank(currencyInfo.getImageUrl())?currencyInfo.getImageUrl():"");
                            exchangeTransactionpair.setCurrencyCoinName(StringUtils.isNotBlank(currencyInfo.getCoinNameCn())?currencyInfo.getCoinNameCn():"");
                        }
                    }
                    //非精选组装
                    List<ExchangeTransactionpair> list = resultMap.get(exchangeTransactionpair.getExchangeName());
                    if(list == null){
                        list = new ArrayList<>();
                    }
                    list.add(exchangeTransactionpair);
                    resultMap.put(exchangeTransactionpair.getExchangeName(),list);
                    //精选组装
                    if(exchangeTransactionpair.getSelected() != null && exchangeTransactionpair.getSelected().intValue() == 1){
                        List<ExchangeTransactionpair> listSelect = resultMap.get("精选");
                        if(listSelect == null){
                            listSelect = new ArrayList<>();
                        }
                        listSelect.add(exchangeTransactionpair);
                        resultMap.put("精选",listSelect);
                    }
                }
                //currencySeaVo.setExchangeTransactionpairsList(middleList);
            }
            //按照顺序返回第一个是精选，其他不排序
            for(Map.Entry<String, List<ExchangeTransactionpair>> map : resultMap.entrySet()){
                ApiTransactionPairSearchVo vo = new ApiTransactionPairSearchVo();
                vo.setTransactionName(map.getKey());
                vo.setExchangeTransactionpairsList(map.getValue());
                if(map.getKey().equals("精选")){
                    resultList.add(0,vo);
                }else{
                    resultList.add(vo);
                }
            }
            //精选搜索
           /* query.setTransactionName(apiCurrencyInfoVo.getCoinNameCn());
            query.setUser_id(user_id);
            query.setSelected(1);
            List<ExchangeTransactionpair> middleSelectList = exchangeTransactionpairMiddleMapper.selectByEntityListOfKLine(query);
            List<ExchangeTransactionpair> jingSelect = new ArrayList<>();*/

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(resultList);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("添加自选-交易对搜索",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }
    /**
     * 添加自选-搜索货币
     * @param apiCurrencyInfoVo
     * @return
     */
    public ApiResultVo addSelfSelectCurrencySea(ApiCurrencyInfoVo apiCurrencyInfoVo) {
        ApiResultVo resultVo=new ApiResultVo();
        try {
            //货币
            //currencySeaVo currencySeaVo=new currencySeaVo();
            Integer user_id = null;
            if(StringUtils.isNotBlank(apiCurrencyInfoVo.getUserToken())){
                user_id = shelSelectService.getRedisUserId(apiCurrencyInfoVo.getUserToken());
            }
            Map<String,Object> params = new HashMap<>();
            params.put("user_id",user_id);
            params.put("coinNameCn",apiCurrencyInfoVo.getCoinNameCn().toUpperCase());
            List<CurrencyInfoApiPo> CurrencyInfoList=currencyInfoMapper.addSelfSelectCurrencySea(params);
            if(CurrencyInfoList.size()>0){
                for(CurrencyInfoApiPo currencyInfo :CurrencyInfoList){
                    if(currencyInfo.getIsSelfSelectId() != null){
                        currencyInfo.setSelfSelectFlag(1);
                    }else{
                        currencyInfo.setSelfSelectFlag(2);
                    }
                }
                //currencySeaVo.setCurrencyInfolist( CurrencyInfoList );
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(CurrencyInfoList);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("货币搜索",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }
    /**
     *
     市场表现
     * @param T t
     * @return List<T>
     */
    public ApiResultVo MarketPer(CurrencyInfo currencyInfo) {
        ApiResultVo resultVo=new ApiResultVo();
        String MARkETPER_INDEX=redisServer.get( RedisKeysUtils.MARkETPER_INDEX+currencyInfo.getCmcId());
        JSONObject js = JSON.parseObject( MARkETPER_INDEX );

        if (js!=null){
            LogTrace.info("市场表现","数据来源","redis");
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(js);
            LogTrace.info("redis 缓存","redis","市场表现");
            return resultVo;
        }

        try {
            String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
            String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
            int hourStrInt = Integer.valueOf(hourStr);
            MarketPerVo vo = new MarketPerVo();
            vo.setClassify("市场表现");
            vo.setSortId(2);
            vo.setExplanation("比较货币价格涨跌幅与大盘指数涨跌幅、行业指数涨跌幅的关系，可以看出当前币种相较于整体市场和行业平均是否处于强势地位。");
            List<String> x=new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            List<ResultValueVo> y2=new ArrayList<>();
            ShiChartVo chartVo=new ShiChartVo();
            Long jStart = System.currentTimeMillis();
            Map<String,String> map=new HashMap<>(  );
            for (int j=0;j<2;j++){
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }

            for (String key : map.keySet()) {
                String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CURRENCY_DIAGNOSIS_MARKET_PERFORMANCE_TABLE_NAME
                        , HbaseTableUtils.CURRENCY_DIAGNOSIS_MARKET_PERFORMANCE_TABLE_FAMILY
                        , HbaseTableUtils.CURRENCY_DIAGNOSIS_MARKET_PERFORMANCE_QUALIFIER
                        , currencyInfo.getCmcId() + "@" + key
                );
                map.put( key,grailStr);
            }

            for (int i = 0; i < 24; i++) {
                String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
                String grailStr=map.get( nowRowKey);
                JSONObject json = JSON.parseObject( grailStr );

                int nowHour = hourStrInt;
                if(hourStrInt == 0){
                    hourStrInt = 23;
                }else{
                    hourStrInt--;
                }
                JSONArray advice = null;

                if (json != null) {
                    advice = (JSONArray) json.getJSONArray( nowHour + "" );
                }

                if (advice != null) {
                    JSONObject jsonObject = (JSONObject) advice.get( advice.size() - 1 );

                    if (jsonObject.containsKey( "priceChangeRate" ))
                        vo.setChange( Double.parseDouble( jsonObject.get( "priceChangeRate" ).toString() )*100);
                    if (jsonObject.containsKey( "broaderChangeRate" ))
                        vo.setMarketChange( Double.parseDouble( jsonObject.get( "broaderChangeRate" ).toString() )*100 );
                    if (jsonObject.containsKey( "industryChangeRate" ))
                        vo.setAverageIndustryIndex( Double.parseDouble( jsonObject.get( "industryChangeRate" ).toString() )*100 );

                    if (jsonObject.containsKey( "createTime" ))
                        vo.setTime( jsonObject.get( "createTime" ).toString() );

                    for (int k = advice.size()-1; k >=0; k--) {
                        JSONObject obj = (JSONObject) advice.get( k );
                        if (obj.containsKey( "createTime" )) x.add( obj.get( "createTime" )+"" );
                        ResultValueVo resuVo = new ResultValueVo();
                        if (obj.containsKey( "priceChangeRate" ))resuVo.setValue( Double.parseDouble( obj.get( "priceChangeRate" ).toString() )*100 );
                        if (obj.containsKey( "comment" ))resuVo.setComment( obj.get( "comment" ).toString()  );
                        y.add( resuVo );
                        ResultValueVo resuVo2=new ResultValueVo();
                        if (obj.containsKey( "comment" ))resuVo2.setComment( obj.get( "comment" ).toString() );
                        if (obj.containsKey( "broaderChangeRate" ))resuVo2.setValue(Double.parseDouble(obj.get( "broaderChangeRate" ).toString()) *100 );
                        y1.add(resuVo2 );
                        ResultValueVo resuVo3=new ResultValueVo();
                        if (obj.containsKey( "comment" ))resuVo3.setComment( obj.get( "comment" ).toString() );
                        if(obj.containsKey( "industryChangeRate" ))resuVo3.setValue(Double.parseDouble(obj.get( "industryChangeRate" ).toString()) *100 );
                        y2.add( resuVo3);
                        chartVo.setX( x );
                        chartVo.setY( y );
                        chartVo.setY1( y1 );
                        chartVo.setY2( y2 );

                    }
                }
            }
            LogTrace.info("市场表现X轴size","X轴",x.size()+"");
            LogTrace.info("市场表现hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));
            vo.setChart(chartVo);

            Collections.reverse(x);
            Collections.reverse(y);
            Collections.reverse(y1);
            Collections.reverse(y2);
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(vo);

            redisServer.set( RedisKeysUtils.MARkETPER_INDEX+currencyInfo.getCmcId(),JSON.toJSONString( vo ),300L);

            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("市场表现",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     压力支撑
     * @param T t
     * @return List<T>
     */
    public ApiResultVo PressureSup(CurrencyInfo currencyInfo){
        ApiResultVo resultVo=new ApiResultVo();

        String PRESSURE_SUP_INDEX=redisServer.get( RedisKeysUtils.PRESSURE_SUP_INDEX+currencyInfo.getCmcId() );

        if(StringUtils.isNotBlank( PRESSURE_SUP_INDEX )){
            JSONObject js=JSON.parseObject( PRESSURE_SUP_INDEX );
            if (js!=null){
                LogTrace.info("压力支撑","数据来源","redis");
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(js);
                return resultVo;
            }
        }

        try {
            //获取当前小时
            String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
            String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
            int hourStrInt = Integer.valueOf(hourStr);

            PressureSupVo vo = new PressureSupVo();
            vo.setClassify("压力支撑");
            vo.setSortId(3);
            vo.setExplanation("支撑位是通过黄金分割原理计算出投资者下跌的心理价位，通常是短期下跌反弹位置，如果连续突破多个支撑位，则表明货币短期内可能走弱。");
            List<String> x=new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            List<ResultValueVo> y2=new ArrayList<>();
            ShiChartVo chartVo=new ShiChartVo();
            Long jStart = System.currentTimeMillis();
            Map<String,String> map=new HashMap<>(  );
            for (int j=0;j<2;j++){
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }
            for (String key : map.keySet()) {
                String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CURRENCY_DIAGNOSIS_PRESSURE_SUPPORT_TABLE_NAME
                        , HbaseTableUtils.CURRENCY_DIAGNOSIS_PRESSURE_SUPPORT_TABLE_FAMILY
                        , HbaseTableUtils.CURRENCY_DIAGNOSIS_PRESSURE_SUPPORT_QUALIFIER
                        , currencyInfo.getCmcId() + "@" + key

                );
                map.put( key,grailStr);
            }

            for (int i=0;i<24;i++){
                String nowRowKey = DateUtils.getLastHourDateStrOfDate(i);
                String grailStr=map.get( nowRowKey);
                JSONObject json = JSON.parseObject( grailStr );

                int nowHour = hourStrInt;
                if(hourStrInt == 0){
                    hourStrInt = 23;
                }else{
                    hourStrInt--;
                }
                JSONArray advice = null;

                if (json != null) {
                    advice = (JSONArray) json.getJSONArray( nowHour + "" );
                }

                if (advice != null) {
                    JSONObject jsonObject = (JSONObject) advice.get(advice.size()-1);

                    if (jsonObject.containsKey("emotionalPressure"))vo.setPressure(Double.parseDouble(jsonObject.get("emotionalPressure").toString()));
                    if (jsonObject.containsKey("marketSupport"))vo.setSupport(Double.parseDouble(jsonObject.get("marketSupport").toString()));
                    if (jsonObject.containsKey("priceCny"))vo.setChange(Double.parseDouble(jsonObject.get("priceCny").toString()));

                    if (jsonObject.containsKey("createTime"))vo.setTime(jsonObject.get("createTime").toString());

                    for(int k = advice.size()-1; k >=0; k--){
                        JSONObject obj = (JSONObject) advice.get(k);
                        if (obj.containsKey("createTime"))x.add(obj.get("createTime").toString());
                        ResultValueVo resuVo=new ResultValueVo();
                        if (obj.containsKey("priceCny"))resuVo.setValue( Double.parseDouble(obj.get("priceCny").toString()) );
                        if (obj.containsKey("comment"))resuVo.setComment( obj.get("comment").toString());
                        y.add( resuVo );
                        ResultValueVo resuVo2=new ResultValueVo();
                        if (obj.containsKey("comment"))resuVo2.setComment( obj.get("comment").toString());
                        if (obj.containsKey("emotionalPressure"))resuVo2.setValue( Double.parseDouble(obj.get("emotionalPressure").toString()));
                        y1.add( resuVo2 );
                        ResultValueVo resuVo3=new ResultValueVo();
                        if (obj.containsKey("comment"))resuVo3.setComment( obj.get("comment").toString());
                        if (obj.containsKey("marketSupport"))resuVo3.setValue( Double.parseDouble(obj.get("marketSupport").toString()));
                        y2.add(resuVo3);
                        chartVo.setX(x);
                        chartVo.setY(y);
                        chartVo.setY1(y1);
                        chartVo.setY2(y2);
                    }
                }
            }
            vo.setChart(chartVo);
            LogTrace.info("压力支撑hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));

            Collections.reverse(x);
            Collections.reverse(y);
            Collections.reverse(y1);
            Collections.reverse(y2);
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(vo);

            redisServer.set( RedisKeysUtils.PRESSURE_SUP_INDEX+currencyInfo.getCmcId(),JSON.toJSONString( vo ),300L);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("压力支撑",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }

    }

    /**
     *
     多空行情
     * @param T t
     * @return List<T>
     */
    public ApiResultVo spaceTrend(CurrencyInfo currencyInfo){
        ApiResultVo resultVo=new ApiResultVo();
        String SPACETREND_INDEX=redisServer.get( RedisKeysUtils.SPACETREND_INDEX+currencyInfo.getCmcId());

        if(StringUtils.isNotBlank( SPACETREND_INDEX )){
            JSONObject   js=JSON.parseObject( SPACETREND_INDEX );
            if (js!=null){
                LogTrace.info("多空行情","数据来源","redis");
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(js);
                return resultVo;
            }
        }

        try {
            //获取当前小时
            String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
            String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
            int hourStrInt = Integer.valueOf(hourStr);

            SpaceTrendVo vo = new SpaceTrendVo();
            vo.setClassify("多空行情");
            vo.setSortId(4);
            vo.setExplanation("当现时价格大于5h平均线和过去24小时平均线时，说明价格突破均线，未来可能继续上涨。当价格跌破均线时，未来可能继续下跌。");
            List<String> x=new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            List<ResultValueVo> y2=new ArrayList<>();
            ShiChartVo chartVo=new ShiChartVo();
            Long jStart = System.currentTimeMillis();
            Map<String,String> map=new HashMap<>(  );
            for (int j=0;j<2;j++){
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }

            for (String key : map.keySet()) {
                String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME
                        , HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME_FAMILY
                        , HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME_QUALIFIER
                        , currencyInfo.getCmcId() + "@" + key
                );
                map.put( key,grailStr);
            }

            for (int j = 0; j < 24; j++) {
                String nowRowKey = DateUtils.getLastHourDateStrOfDate(j);
                String grailStr=map.get( nowRowKey);
                JSONObject json = JSON.parseObject( grailStr );

                int nowHour = hourStrInt;
                if(hourStrInt == 0){
                    hourStrInt = 23;
                }else{
                    hourStrInt--;
                }
                JSONArray advice = null;

                if (json!=null) {
                    advice = (JSONArray) json.getJSONArray(nowHour + "");
                }
                if (advice != null) {
                    JSONObject jsonObject = (JSONObject) advice.get( advice.size() - 1 );
                    if (jsonObject.containsKey( "createTime" ))
                        vo.setTime( jsonObject.get( "createTime" ).toString() );
                    for (int k = advice.size()-1; k >=0; k--) {
                        JSONObject obj = (JSONObject) advice.get( k );
                        if (obj.containsKey( "createTime" )) x.add( obj.get( "createTime" ).toString() );

                        ResultValueVo resuVo=new ResultValueVo();
                        if (obj.containsKey( "priceCny" ))resuVo.setValue(Double.parseDouble( obj.get( "priceCny" ).toString() ));
                        if(obj.containsKey( "comment" ))resuVo.setComment( obj.get( "comment" ).toString() );
                        y.add( resuVo);

                        ResultValueVo resuVo2=new ResultValueVo();
                        if (obj.containsKey("comment"))resuVo2.setComment( obj.get("comment").toString());
                        if (obj.containsKey("avg2PriceCny"))resuVo2.setValue(Double.parseDouble( obj.get("avg2PriceCny").toString()));//过去24小时平均价
                        y1.add( resuVo2 );

                        ResultValueVo resuVo3=new ResultValueVo();
                        if (obj.containsKey("comment"))resuVo3.setComment(obj.get("comment").toString());
                        if (obj.containsKey( "avg1PriceCny" ))resuVo3.setValue(Double.parseDouble( obj.get("avg1PriceCny").toString()));//过去5小时平均价
                        y2.add( resuVo3);
                        chartVo.setX( x );
                        chartVo.setY( y );
                        chartVo.setY1( y1 );
                        chartVo.setY2( y2 );
                    }
                }
            }

            LogTrace.info("多空行情hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));
            vo.setChart(chartVo);

            Collections.reverse(x);
            Collections.reverse(y);
            Collections.reverse(y1);
            Collections.reverse(y2);
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(vo);

            redisServer.set( RedisKeysUtils.SPACETREND_INDEX+currencyInfo.getCmcId(),JSON.toJSONString( vo ),300L);

            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("多空行情",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     平均成本
     * @param T t
     * @return List<T>
     */
    public ApiResultVo avgCost(CurrencyInfo currencyInfo){
        ApiResultVo resultVo=new ApiResultVo();
        Long jStart = System.currentTimeMillis();

        String AVG_COST_INDEX=redisServer.get( RedisKeysUtils.AVG_COST_INDEX+currencyInfo.getCmcId() );
        if(StringUtils.isNotBlank( AVG_COST_INDEX )){
            JSONObject   js=JSON.parseObject( AVG_COST_INDEX );

            if (js!=null){
                LogTrace.info("平均成本","数据来源","redis");
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(js);
                LogTrace.info("redis 缓存","redis","js2");
                return resultVo;
            }
        }

        try {
            String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
            String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
            int hourStrInt = Integer.valueOf(hourStr);

            AvgCostVo vo = new AvgCostVo();

            vo.setClassify("平均成本");
            vo.setSortId(1);
            vo.setExplanation("计算近一个小时的移动平均价格，通过分析现时价格与平均成本的关系，可以看出近期交易的投资者整体是盈利还是亏损。");
            List<String> x=new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            AvgChartVo chartVo=new AvgChartVo();
            Map<String,String> map=new HashMap<>(  );
            for (int j=0;j<2;j++){
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }

            for (String key : map.keySet()) {
                String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CURRENCY_DIAGNOSIS_AVERAGE_COST_INFO_TABLE_NAME
                        , HbaseTableUtils.CURRENCY_DIAGNOSIS_AVERAGE_COST_INFO_TABLE_FAMILY
                        , HbaseTableUtils.CURRENCY_DIAGNOSIS_AVERAGE_COST_INFO_QUALIFIER
                        , currencyInfo.getCmcId() + "@" + key
                );
                map.put( key,grailStr);
                LogTrace.info( "平均成本...",key, grailStr!=null?"1":"0");
            }

            for (int j = 0; j < 24; j++) {
                String nowRowKey = DateUtils.getLastHourDateStrOfDate(j);
                String grailStr=map.get( nowRowKey);
                JSONObject json = JSON.parseObject( grailStr );

                int nowHour = hourStrInt;
                if(hourStrInt == 0){
                    hourStrInt = 23;
                }else{
                    hourStrInt--;
                }
                JSONArray advice = null;

                if (json != null) {
                    advice = (JSONArray) json.getJSONArray( nowHour + "" );
                }
                if (advice != null) {
                    JSONObject jsonObject = (JSONObject) advice.get( advice.size() - 1 );
                    if (jsonObject.containsKey( "createTime" ))
                        vo.setTime( jsonObject.get( "createTime" ).toString() );

                    for (int k = advice.size()-1; k >=0; k--) {
                        JSONObject obj = (JSONObject) advice.get( k );
                        if (obj.containsKey( "createTime" )) x.add( obj.get( "createTime" ).toString() );

                        ResultValueVo resuVo=new ResultValueVo();
                        if (obj.containsKey( "priceCny" ))resuVo.setValue( Double.parseDouble( obj.get( "priceCny" ).toString() ) );
                        if (obj.containsKey( "comment" ))resuVo.setComment(  obj.get( "comment" ).toString()  );
                        y.add( resuVo );

                        ResultValueVo resuVo2=new ResultValueVo();
                        if (obj.containsKey( "comment" ))resuVo2.setComment(obj.get( "comment" ).toString() );
                        if (obj.containsKey( "diagnosisAverageCost" ))resuVo2.setValue( Double.parseDouble( obj.get( "diagnosisAverageCost" ).toString() ) );
                        y1.add( resuVo2 );
                        chartVo.setX( x );
                        chartVo.setY( y );
                        chartVo.setY1( y1 );
                    }
                }
            }
            LogTrace.info("平均成本X轴size","X轴",x.size()+"");


            LogTrace.info("平均成本hbase查询","耗时",String.valueOf(System.currentTimeMillis()-jStart));
            vo.setChart(chartVo);
            Collections.reverse(x);
            Collections.reverse(y);
            Collections.reverse(y1);
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(vo);

            redisServer.set( RedisKeysUtils.AVG_COST_INDEX+currencyInfo.getCmcId(),JSON.toJSONString( vo ),300L);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("平均成本",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     研报列表
     * @param T t
     * @return List<T>
     */
    public ApiResultVo reportList(){
        ApiResultVo resultVo=new ApiResultVo();
        try {

            SyResearchReport syResearchReport=new SyResearchReport();
            syResearchReport.setEnableFlag(true);
            syResearchReport.setDeleteFlag(false);
            syResearchReport.setPublishPlatform( "1" );
            List<SyResearchReport> list=syResearchReportMapper.getReportAllList(syResearchReport);

            for (int i=0;i<list.size();i++){
                List<String> strList=new ArrayList<>();
                SyResearchReport syRe=new SyResearchReport();
                syRe.setId(list.get(i).getId());
                List<SyResearchReport> syList=syResearchReportMapper.getReportList(syRe);
                for (int j = 0; j < syList.size(); j++) {
                    SyResearchReport report = syList.get(j);
                    if (report!=null){
                        strList.add(syList.get(j).getChannelsName());
                    }
                }
                List<String> imgList=new ArrayList<>();
                SyResearchReportFile syResearchReportFile=new SyResearchReportFile();
                syResearchReportFile.setResearchReportId(list.get(i).getId());
                syResearchReportFile.setType(0);
                syResearchReportFile.setDeleteFlag( false );
                syResearchReportFile.setPublishPlatform( "1" );
                List<SyResearchReportFile> fileList=syResearchReportFileMapper.selectByEntityList(syResearchReportFile);
                for (int j = 0; j < fileList.size(); j++) {
                    SyResearchReportFile file=fileList.get(j);
                    if(file!=null){
                        if(fileList.get(j).getFileName()!=null&&fileList.get(j).getFileName().contains( "http" )){
                            imgList.add(fileList.get(j).getFileName());
                        }else{
                            String imgUrl=ossImageUtil.fmtImg( fileList.get(j).getFileName() );
                            imgList.add( imgUrl );
                        }
                    }
                }

                SyChannels syChannels=new SyChannels();
                List<String> chalStrList=new ArrayList<>();
                syChannels.setId( list.get( i ).getChannelsId() );
                syChannels.setEnableFlag( true );
                syChannels.setDeleteFlag( false );
                List<SyChannels> challList=syChannelsMapper.selectByEntityList(syChannels);
                for (int j=0;j<challList.size();j++){
                    chalStrList.add(  challList.get( j ).getName());
                }

                list.get( i ).setPdList( chalStrList );
                list.get(i).setChannelsNames(strList);
                list.get(i).setImgList(imgList);

            }

            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(list);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("研报列表",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     研报浏览排行列表
     * @param T t
     * @return List<T>
     */
    public ApiResultVo reportTourRankList(){
        ApiResultVo resultVo=new ApiResultVo();
        try {
            List<SyResearchReport> list=syResearchReportMapper.getReportTourRankList();
            for (int i=0;i<list.size();i++){
                SyResearchReport syResearchReport=list.get( i );
                SyChannels sc=new SyChannels();
                sc.setId( syResearchReport.getChannelsId() );
                sc.setDeleteFlag( false );
                sc.setEnableFlag( true );
                List<SyChannels> syList = syChannelsMapper.selectByEntityList( sc );
                if (syList.size()>0){
                    if (StringUtils.isNotBlank( syList.get( 0 ).getName() )){
                        syResearchReport.setName( syList.get( 0 ).getName() );
                    }
                }
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(list);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("研报浏览排行列表",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     研报下载排行列表
     * @param T t
     * @return List<T>
     */
    public ApiResultVo reportDownloadRankList(){
        ApiResultVo resultVo=new ApiResultVo();
        try {
            List<SyResearchReport> list=syResearchReportMapper.getReportDownloadRankList();
            for (int i=0;i<list.size();i++){
                SyResearchReport syResearchReport=list.get( i );
                SyChannels sc=new SyChannels();
                sc.setId( syResearchReport.getChannelsId() );
                sc.setDeleteFlag( false );
                sc.setEnableFlag( true );
                List<SyChannels> syList = syChannelsMapper.selectByEntityList( sc );
                if (syList.size()>0){
                    if (StringUtils.isNotBlank( syList.get( 0 ).getName() )){
                        syResearchReport.setName( syList.get( 0 ).getName() );
                    }
                }
            }
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            resultVo.setData(list);
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("研报下载排行列表",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     研报详情
     * @param T t
     * @return List<T>
     */
    public ApiResultVo reportDetails(SyResearchReport syResearchReport){
        ApiResultVo resultVo=new ApiResultVo();
        try {
            List<SyResearchReport> list=syResearchReportMapper.selectByEntityList(syResearchReport);

            if (list.size()>0){
                SyResearchReportFile file=new SyResearchReportFile();
                file.setType( 1 );
                file.setResearchReportId( list.get( 0 ).getId() );
                file.setPublishPlatform( "1" );
                List<SyResearchReportFile> fileList= syResearchReportFileMapper.selectByEntityList(file);

                List<String> strList=new ArrayList<>(  );

                for (int i=0;i<fileList.size();i++){
                    String filePath = fileList.get( i ).getFileName();
                    if(StringUtils.isNotBlank( filePath )&&filePath.contains( "http" )){
                        strList.add( fileList.get( i ).getFileName());
                    }else{
                        String imgUrl=ossImageUtil.fmtImg( filePath );
                        strList.add( imgUrl );
                    }
                }

                list.get(0).setFilePath( strList );
                //浏览次数+1
                syResearchReportMapper.updateTourCount(syResearchReport);

                list.get( 0 ).setContent( list.get( 0 ).getContent().replace("OSSAccessKeyId" , "" ) );
                SyChannels syChannels=new SyChannels();
                List<String> chalStrList=new ArrayList<>();
                syChannels.setId( list.get( 0 ).getId() );
                syChannels.setEnableFlag( true );
                syChannels.setDeleteFlag( false );
                List<SyChannels> challList=syChannelsMapper.selectByEntityList(syChannels);
                for (int j=0;j<challList.size();j++){
                    chalStrList.add(  challList.get( j ).getName());
                }
                list.get(0).setPdList( chalStrList );
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(list.get(0));
            }else {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            }
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("研报详情",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     研报下载
     * @param T t
     * @return List<T>
     */
    public ApiResultVo reportDownload(SyResearchReportFile syResearchReportFile){
        ApiResultVo resultVo=new ApiResultVo();
        try {
            SyResearchReportFile syResearchReportFile2=new SyResearchReportFile();
            syResearchReportFile2.setDeleteFlag( false );
            syResearchReportFile2.setResearchReportId( syResearchReportFile.getId() );
            List<SyResearchReportFile> list=syResearchReportFileMapper.selectByEntityList(syResearchReportFile2);

            if (list.size()>0){
                //下载次数+1
                SyResearchReport syResearchReport=new SyResearchReport();
                syResearchReport.setId(list.get(0).getResearchReportId());
                syResearchReportMapper.updateDownloadCount(syResearchReport);

                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(list.get(0));
            }else {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            }
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("研报下载",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     研报推荐
     * @param T t
     * @return List<T>
     */
    public ApiResultVo recommend(){
        ApiResultVo resultVo=new ApiResultVo();
        try {
            List<SyResearchReport> list=syResearchReportMapper.getRecommend();
            for (int i=0;i<list.size();i++){
                SyResearchReport syResearchReport=list.get( i );
                SyChannels sc=new SyChannels();
                sc.setId( syResearchReport.getChannelsId() );
                sc.setDeleteFlag( false );
                sc.setEnableFlag( true );
                List<SyChannels> syList = syChannelsMapper.selectByEntityList( sc );
                if (syList.size()>0){
                    if (StringUtils.isNotBlank( syList.get( 0 ).getName() )){
                        syResearchReport.setName( syList.get( 0 ).getName() );
                    }
                }
            }

            if (list.size()>0){
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(list);
            }else {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            }
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("研报推荐",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }

    /**
     *
     研报banner图
     * @param T t
     * @return List<T>
     */
    public ApiResultVo bannerList(){
        ApiResultVo resultVo=new ApiResultVo();
        try {
            List<SyRotationMap> list=syRotationMapMapper.getBannerList();

            if (list.size()>0){
                resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
                resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
                resultVo.setData(list);
            }else {
                resultVo.setCode(ApiResultCodeUtils.SYSTEM_NULL.getCode());
                resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
                resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            }
            return resultVo;
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("研报banner图",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
    }


    /**
     *
     组装平均成本数据
     * @param T t
     * @return List<T>
     */
    public ApiResultVo getAvgCost() {
        CurrencyInfo info=new CurrencyInfo();
        info.setEnableFlag( true );
        info.setDeleteFlag( false );
        List<CurrencyInfo> currencyInfosList=currencyInfoMapper.selectByEntityList( info );
        ApiResultVo resultVo=new ApiResultVo();

        try {
            String nowDateHoursStr = DateUtils.dateFormatString( new Date(), DateUtils.format_ymdh_x );
            String hourStr = nowDateHoursStr.substring( nowDateHoursStr.length() - 2, nowDateHoursStr.length() );
            int hourStrInt = Integer.valueOf( hourStr );

            AvgCostVo vo = new AvgCostVo();

            vo.setClassify( "平均成本" );
            vo.setSortId( 1 );
            vo.setExplanation("计算近一个小时的移动平均价格，通过分析现时价格与平均成本的关系，可以看出近期交易的投资者整体是盈利还是亏损。");
            List<String> x = new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            AvgChartVo chartVo = new AvgChartVo();
            Map<String, String> map = new HashMap<>();
            for (int j = 0; j < 2; j++) {
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }

            for (int i=0;i<currencyInfosList.size();i++){
                for (String key : map.keySet()) {
                    String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME
                            , HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME_FAMILY
                            , HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME_QUALIFIER
                            , currencyInfosList.get( i ).getCmcId() + "@" + key
                    );
                    map.put( key, grailStr );
                }

                for (int j = 0; j < 24; j++) {
                    String nowRowKey = DateUtils.getLastHourDateStrOfDate( j );
                    String grailStr = map.get( nowRowKey );
                    JSONObject json = JSON.parseObject( grailStr );

                    int nowHour = hourStrInt;
                    if (hourStrInt == 0) {
                        hourStrInt = 23;
                    } else {
                        hourStrInt--;
                    }
                    JSONArray advice = null;

                    if (json != null) {
                        advice = (JSONArray) json.getJSONArray( hourStrInt + "" );
                    }
                    if (advice != null) {
                        JSONObject jsonObject = (JSONObject) advice.get( advice.size() - 1 );
                        if (jsonObject.containsKey( "createTime" ))
                            vo.setTime( jsonObject.get( "createTime" ).toString() );

                        for (int k = advice.size() - 1; k >= 0; k--) {
                            JSONObject obj = (JSONObject) advice.get( k );
                            if (obj.containsKey( "createTime" )) x.add( obj.get( "createTime" ).toString() );

                            ResultValueVo resuVo=new ResultValueVo();
                            if (obj.containsKey( "priceCny" ))resuVo.setValue( Double.parseDouble( obj.get( "priceCny" ).toString() ) );
                            if (obj.containsKey( "comment" ))resuVo.setComment(  obj.get( "comment" ).toString()  );
                            y.add( resuVo );

                            ResultValueVo resuVo2=new ResultValueVo();
                            if (obj.containsKey( "comment" ))resuVo2.setComment(obj.get( "comment" ).toString() );
                            if (obj.containsKey( "diagnosisAverageCost" ))resuVo2.setValue( Double.parseDouble( obj.get( "diagnosisAverageCost" ).toString() ) );
                            y1.add( resuVo2 );
                        }
                    }
                }
                Collections.reverse(x);
                Collections.reverse(y);
                Collections.reverse(y1);
                chartVo.setX( x );
                chartVo.setY( y );
                chartVo.setY1( y1 );
                vo.setChart(chartVo);
                redisServer.set( RedisKeysUtils.AVG_COST_INDEX+currencyInfosList.get( i ).getCmcId(),JSON.toJSONString( vo ),300L);
                x= new ArrayList<>();
                y=new ArrayList<>();
                y1=new ArrayList<>();
                chartVo=new AvgChartVo();
                vo =  new AvgCostVo();
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("平均成本",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  null;
    }

    /**
     *
     组装多空行情数据存redis
     * @param T t
     * @return List<T>
     */
    public ApiResultVo getSpaceTrend(){
        CurrencyInfo info=new CurrencyInfo();
        info.setEnableFlag( true );
        info.setDeleteFlag( false );
        List<CurrencyInfo> currencyInfosList=currencyInfoMapper.selectByEntityList( info );
        ApiResultVo resultVo=new ApiResultVo();
        try {
            //获取当前小时
            String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
            String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
            int hourStrInt = Integer.valueOf(hourStr);

            SpaceTrendVo vo = new SpaceTrendVo();
            vo.setClassify("多空行情");
            vo.setSortId(4);
            vo.setExplanation("当现时价格大于5h平均线和过去24小时平均线时，说明价格突破均线，未来可能继续上涨。当价格跌破均线时，未来可能继续下跌。");
            List<String> x=new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            List<ResultValueVo> y2=new ArrayList<>();
            ShiChartVo chartVo=new ShiChartVo();
            Long jStart = System.currentTimeMillis();
            Map<String,String> map=new HashMap<>(  );
            Map<String, SpaceTrendVo> resultMap = new HashMap<>();

            for (int j = 0; j < 2; j++) {
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }

            for (int i=0;i<currencyInfosList.size();i++) {

                for (String key : map.keySet()) {
                    String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME
                            , HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME_FAMILY
                            , HbaseTableUtils.LONG_AND_SHORT_TREND_TABLE_NAME_QUALIFIER
                            , currencyInfosList.get( i ).getCmcId() + "@" + key
                    );
                    map.put( key, grailStr );
                }

                for (int j = 0; j < 24; j++) {
                    String nowRowKey = DateUtils.getLastHourDateStrOfDate( j );
                    String grailStr = map.get( nowRowKey );
                    JSONObject json = JSON.parseObject( grailStr );

                    int nowHour = hourStrInt;
                    if (hourStrInt == 0) {
                        hourStrInt = 23;
                    } else {
                        hourStrInt--;
                    }
                    JSONArray advice = null;

                    if (json != null) {
                        advice = (JSONArray) json.getJSONArray( nowHour + "" );
                    }

                    if (advice != null) {
                        JSONObject jsonObject = (JSONObject) advice.get( advice.size() - 1 );

                        for (int k = advice.size() - 1; k >= 0; k--) { JSONObject obj = (JSONObject) advice.get( k );
                            if (obj.containsKey( "createTime" )) x.add( obj.get( "createTime" ).toString() );

                            ResultValueVo resuVo=new ResultValueVo();
                            if (obj.containsKey( "priceCny" ))resuVo.setValue(Double.parseDouble( obj.get( "priceCny" ).toString() ));
                            if(obj.containsKey( "comment" ))resuVo.setComment( obj.get( "comment" ).toString() );
                            y.add( resuVo);

                            ResultValueVo resuVo2=new ResultValueVo();
                            if (obj.containsKey("comment"))resuVo2.setComment( obj.get("comment").toString());
                            if (obj.containsKey( "avg2PriceCny" ))resuVo2.setValue( Double.parseDouble( obj.get( "avg2PriceCny" ).toString() ));
                            y1.add( resuVo2 );

                            ResultValueVo resuVo3=new ResultValueVo();
                            if (obj.containsKey("comment"))resuVo3.setComment( obj.get("comment").toString());
                            if (obj.containsKey( "avg1PriceCny" ))resuVo2.setValue( Double.parseDouble( obj.get( "avg1PriceCny" ).toString() ) );
                            y2.add( resuVo3);
                        }
                    }
                }
                Collections.reverse(x);
                Collections.reverse(y);
                Collections.reverse(y1);
                Collections.reverse(y2);
                chartVo.setX( x );
                chartVo.setY( y );
                chartVo.setY1( y1 );
                chartVo.setY2( y2 );
                vo.setChart(chartVo);
                redisServer.set( RedisKeysUtils.SPACETREND_INDEX+currencyInfosList.get( i ).getCmcId(),JSON.toJSONString( vo ),300L);

                x= new ArrayList<>();
                y=new ArrayList<>();
                y1=new ArrayList<>();
                y2=new ArrayList<>();
                chartVo=new ShiChartVo();
                vo =  new SpaceTrendVo();
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("多空行情",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  null;
    }

    /**
     *
     组装压力支撑数据存redis
     * @param T t
     * @return List<T>
     */
    public ApiResultVo getPressureSup(){ CurrencyInfo info=new CurrencyInfo();
        info.setEnableFlag( true );
        info.setDeleteFlag( false );
        List<CurrencyInfo> currencyInfosList=currencyInfoMapper.selectByEntityList( info );
        ApiResultVo resultVo=new ApiResultVo();
        try {
            //获取当前小时
            String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
            String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
            int hourStrInt = Integer.valueOf(hourStr);

            PressureSupVo vo = new PressureSupVo();
            vo.setClassify("压力支撑");
            vo.setSortId(3);
            vo.setExplanation("支撑位是通过黄金分割原理计算出投资者下跌的心理价位，通常是短期下跌反弹位置，如果连续突破多个支撑位，则表明货币短期内可能走弱。");
            List<String> x=new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            List<ResultValueVo> y2=new ArrayList<>();
            ShiChartVo chartVo=new ShiChartVo();
            Map<String,String> map=new HashMap<>(  );
            for (int j = 0; j < 2; j++) {
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }

            for (int i=0;i<currencyInfosList.size();i++) {

                for (String key : map.keySet()) {
                    String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CURRENCY_DIAGNOSIS_PRESSURE_SUPPORT_TABLE_NAME
                            , HbaseTableUtils.CURRENCY_DIAGNOSIS_PRESSURE_SUPPORT_TABLE_FAMILY
                            , HbaseTableUtils.CURRENCY_DIAGNOSIS_PRESSURE_SUPPORT_QUALIFIER
                            , currencyInfosList.get( i ).getCmcId() + "@" + key

                    );
                    map.put( key, grailStr );
                }

                for (int j = 0; j < 24; j++) {
                    String nowRowKey = DateUtils.getLastHourDateStrOfDate( j );
                    String grailStr = map.get( nowRowKey );
                    JSONObject json = JSON.parseObject( grailStr );

                    int nowHour = hourStrInt;
                    if (hourStrInt == 0) {
                        hourStrInt = 23;
                    } else {
                        hourStrInt--;
                    }
                    JSONArray advice = null;

                    if (json != null) {
                        advice = (JSONArray) json.getJSONArray( nowHour + "" );
                    }

                    if (advice != null) {
                        JSONObject jsonObject = (JSONObject) advice.get( advice.size() - 1 );
                        if (jsonObject.containsKey( "createTime" ))
                            vo.setTime( jsonObject.get( "createTime" ).toString() );

                        for (int k = advice.size() - 1; k >= 0; k--) {
                            JSONObject obj = (JSONObject) advice.get(k);
                            if (obj.containsKey("createTime"))x.add(obj.get("createTime").toString());
                            ResultValueVo resuVo=new ResultValueVo();
                            if (obj.containsKey("priceCny"))resuVo.setValue( Double.parseDouble(obj.get("priceCny").toString()) );
                            if (obj.containsKey("comment"))resuVo.setComment( obj.get("comment").toString());
                            y.add( resuVo );
                            ResultValueVo resuVo2=new ResultValueVo();
                            if (obj.containsKey("comment"))resuVo2.setComment( obj.get("comment").toString());
                            if (obj.containsKey("emotionalPressure"))resuVo2.setValue( Double.parseDouble(obj.get("emotionalPressure").toString()));
                            y1.add( resuVo2 );
                            ResultValueVo resuVo3=new ResultValueVo();
                            if (obj.containsKey("comment"))resuVo3.setComment( obj.get("comment").toString());
                            if (obj.containsKey("marketSupport"))resuVo3.setValue( Double.parseDouble(obj.get("marketSupport").toString()));
                            y2.add(resuVo3);
                        }
                    }
                }
                Collections.reverse(x);
                Collections.reverse(y);
                Collections.reverse(y1);
                Collections.reverse(y2);
                chartVo.setX(x);
                chartVo.setY(y);
                chartVo.setY1(y1);
                chartVo.setY2(y2);
                vo.setChart(chartVo);
                redisServer.set( RedisKeysUtils.PRESSURE_SUP_INDEX+currencyInfosList.get( i ).getCmcId(),  JSON.toJSONString(  vo),300L);
                x= new ArrayList<>();
                y=new ArrayList<>();
                y1=new ArrayList<>();
                y2=new ArrayList<>();
                chartVo=new ShiChartVo();
                vo =  new PressureSupVo();
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("压力支撑",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  null;
    }


    /**
     *
     市场表现存取
     * @param T t
     * @return List<T>
     */
    public ApiResultVo getMarketPer() {
        CurrencyInfo info=new CurrencyInfo();
        info.setEnableFlag( true );
        info.setDeleteFlag( false );
        List<CurrencyInfo> currencyInfosList=currencyInfoMapper.selectByEntityList( info );
        ApiResultVo resultVo=new ApiResultVo();

        try {
            String nowDateHoursStr = DateUtils.dateFormatString(new Date(),DateUtils.format_ymdh_x);
            String hourStr = nowDateHoursStr.substring(nowDateHoursStr.length()-2,nowDateHoursStr.length());
            int hourStrInt = Integer.valueOf(hourStr);
            MarketPerVo vo = new MarketPerVo();
            vo.setClassify("市场表现");
            vo.setSortId(2);
            vo.setExplanation("比较货币价格涨跌幅与大盘指数涨跌幅、行业指数涨跌幅的关系，可以看出当前币种相较于整体市场和行业平均是否处于强势地位。");
            List<String> x=new ArrayList<>();
            List<ResultValueVo> y=new ArrayList<>();
            List<ResultValueVo> y1=new ArrayList<>();
            List<ResultValueVo> y2=new ArrayList<>();
            ShiChartVo chartVo=new ShiChartVo();
            Long jStart = System.currentTimeMillis();
            Map<String,String> map=new HashMap<>(  );

            for (int j=0;j<2;j++){
                String rowkey = DateUtils.getNextDayDateYMD(-j);//取rowkey
                map.put( rowkey,rowkey );
            }

            for (int l=0;l<currencyInfosList.size();l++) {
                for (String key : map.keySet()) {
                    String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CURRENCY_DIAGNOSIS_MARKET_PERFORMANCE_TABLE_NAME
                            , HbaseTableUtils.CURRENCY_DIAGNOSIS_MARKET_PERFORMANCE_TABLE_FAMILY
                            , HbaseTableUtils.CURRENCY_DIAGNOSIS_MARKET_PERFORMANCE_QUALIFIER
                            , currencyInfosList.get( l ).getCmcId() + "@" + key
                    );
                    map.put( key, grailStr );
                }

                for (int i = 0; i < 24; i++) {
                    String nowRowKey = DateUtils.getLastHourDateStrOfDate( i );
                    String grailStr = map.get( nowRowKey );
                    JSONObject json = JSON.parseObject( grailStr );

                    int nowHour = hourStrInt;
                    if (hourStrInt == 0) {
                        hourStrInt = 23;
                    } else {
                        hourStrInt--;
                    }
                    JSONArray advice = null;

                    if (json != null) {
                        advice = (JSONArray) json.getJSONArray( nowHour + "" );
                    }

                    if (advice != null) {
                        JSONObject jsonObject = (JSONObject) advice.get( advice.size() - 1 );
                        if (jsonObject.containsKey( "createTime" ))
                            vo.setTime( jsonObject.get( "createTime" ).toString() );

                        for (int k = advice.size() - 1; k >= 0; k--) {       JSONObject obj = (JSONObject) advice.get( k );
                            if (obj.containsKey( "createTime" )) x.add( obj.get( "createTime" )+"" );
                            ResultValueVo resuVo = new ResultValueVo();
                            if (obj.containsKey( "priceChangeRate" ))resuVo.setValue( Double.parseDouble( obj.get( "priceChangeRate" ).toString() )*100 );
                            if (obj.containsKey( "comment" ))resuVo.setComment( obj.get( "comment" ).toString()  );
                            y.add( resuVo );
                            ResultValueVo resuVo2=new ResultValueVo();
                            if (obj.containsKey( "comment" ))resuVo2.setComment( obj.get( "comment" ).toString() );
                            if (obj.containsKey( "broaderChangeRate" ))resuVo2.setValue(Double.parseDouble(obj.get( "broaderChangeRate" ).toString()) *100 );
                            y1.add(resuVo2 );
                            ResultValueVo resuVo3=new ResultValueVo();
                            if (obj.containsKey( "comment" ))resuVo3.setComment( obj.get( "comment" ).toString() );
                            if(obj.containsKey( "industryChangeRate" ))resuVo3.setValue(Double.parseDouble(obj.get( "industryChangeRate" ).toString()) *100 );
                            y2.add( resuVo3);

                        }
                    }
                }

                Collections.reverse(x);
                Collections.reverse(y);
                Collections.reverse(y1);
                Collections.reverse(y2);
                chartVo.setX( x );
                chartVo.setY( y );
                chartVo.setY1( y1 );
                chartVo.setY2( y2 );
                vo.setChart( chartVo );
                redisServer.set( RedisKeysUtils.MARkETPER_INDEX+currencyInfosList.get( l ).getCmcId(),JSON.toJSONString( vo ),300L);
                x= new ArrayList<>();
                y=new ArrayList<>();
                y1=new ArrayList<>();
                y2=new ArrayList<>();

                chartVo=new ShiChartVo();
                vo =  new MarketPerVo();
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("市场表现",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  null;
    }


    /**
     *
     平台币概念指数
     * @param T t
     * @return List<T>
     */
    public ApiResultVo getBottomteZhi() {
        ApiResultVo resultVo=new ApiResultVo();
        Long jStart = System.currentTimeMillis();
        ConceptCategory conceptCategory=new ConceptCategory();
        conceptCategory.setEnableFlag( true );
        conceptCategory.setDeleteFlag( false );
        List<ConceptCategory>  conList=conceptCategoryMapper.selectByEntityList( conceptCategory );
        try {
            for (int k=0;k<conList.size();k++) {
                String rowkey = conList.get( k ).getId() + "@" + DateUtils.getCurrentDateString();
                String grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CONCEPTUAL_QUOTES_TABLE_NAME
                        , HbaseTableUtils.CONCEPTUAL_QUOTES_TABLE_NAME_FAMILY
                        , HbaseTableUtils.CONCEPTUAL_QUOTES_TABLE_NAME_QUALIFIER
                        , rowkey
                );
                LogTrace.info( "平台币概念指数hbase查询", "耗时", String.valueOf( System.currentTimeMillis() - jStart + ":" + rowkey ) );
                JSONObject json = JSON.parseObject( grailStr );

                List list = new ArrayList();
                List<String> x = new ArrayList<>();

                GaiNianZhiShuVo vo = new GaiNianZhiShuVo();
                List<GaiNianYVo> voList = new ArrayList<>();
                for (int i = 0; i < 24; i++) {
                    JSONArray advice = null;
                    if (json != null) {
                        advice = (JSONArray) json.getJSONArray( i + "" );
                    }
                    if (advice != null) {
                        JSONObject obj = (JSONObject) advice.get( advice.size() - 1 );

                        GaiNianYVo gaiNianYVo = new GaiNianYVo();
                        if (obj.containsKey( "createTime" )) {
                            long timeStamp = Long.parseLong( obj.get( "createTime" ).toString() );  //获取当前时间戳,也可以是你自已给的一个随机的或是别人给你的时间戳(一定是long型的数据)
                            x.add( obj.get( "createTime" ).toString() );
                            SimpleDateFormat sdf2 = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );//这个是你要转成后的时间的格式
                            String sd2 = sdf2.format( new Date( Long.parseLong( String.valueOf( timeStamp ) ) ) );   // 时间戳转换成时间
                            vo.setDate( sd2 );
                        }

                        if (obj.containsKey( "conceptIndex" ))
                            gaiNianYVo.setValue( obj.get( "conceptIndex" ).toString() );
                        if (obj.containsKey( "avgPercentChange24h" ))
                            gaiNianYVo.setChange( obj.get( "avgPercentChange24h" ).toString() );
                        voList.add( gaiNianYVo );
                    }
                }
                vo.setX( x );
                vo.setY( voList );
                list.add( vo );
                redisServer.set( RedisKeysUtils.BOTTOMTEZHI_INDEX+conList.get( k ).getId(),JSON.toJSONString( list ),300L);
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("平台币概念指数",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  null;
    }


    /**
     * 货币诊断排名前5
     * @param T t
     * @return List<T>
     */
    public ApiResultVo getMonetarydiagnosisTop5() {
        ApiResultVo resultVo=new ApiResultVo();

        try {
            Date date =new Date();
            SimpleDateFormat sdf =new SimpleDateFormat("HH:mm:ss");//只有时分秒
            String time=sdf.format(date);
            String hour=time.substring(0,2);

            String curentcyHigh=redisServer.get(RedisKeysUtils.COIN_RANK);
            CoinRank coinRank=JSON.parseObject(curentcyHigh, CoinRank.class);

            List<MoneyDiagnosisTop5Vo> hotList=new ArrayList<>(  );
            Map<String,MoneyDiagnosisTop5Vo> map=new HashedMap();
            if (coinRank.getMarketCapRankList().size()>=5) {
                for (int i = 0; i < 5; i++) {
                    CmcCurrencyInfo cyInfo = coinRank.getMarketCapRankList().get( i );
                    String grailStr =null;
                    int d=0;
                    while(grailStr==null){
                        grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_TABLE_NAME
                                , HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_TABLE_FAMILY
                                , HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_QUALIFIER
                                , cyInfo.getId() + "@" + (Integer.parseInt(DateUtils.getCurrentDateString())-d)
                        );
                        if (grailStr!=null){
                            break;
                        }
                        d++;
                    }

                    JSONObject json = JSON.parseObject( grailStr );
                    JSONArray advice = null;
                    if (json != null) {
                        Set<String> setString=json.keySet();
                        Iterator it1 = setString.iterator();
                        String lastKey=null;
                        while(it1.hasNext()){
                            lastKey=it1.next()+"";
                        }
                        advice = (JSONArray) json.getJSONArray( lastKey );
                    }

                    if (advice != null) {
                        List<DiagnosisScore> diaList = JSON.parseArray( advice.toJSONString(), DiagnosisScore.class );
                        DiagnosisScore score = diaList.get( diaList.size() - 1 );
                        List<Integer> intList = new ArrayList<>();
                        MoneyDiagnosisTop5Vo topVo = new MoneyDiagnosisTop5Vo();
                        topVo.setScore( score.getDiagnosisScore().toString().substring( 0, 3 ) );
                        CurrencyInfo info = redisCacheComponent.getCurrencyInfo( score.getId() );
                        topVo.setDiagnosisId( score.getId() );
                        topVo.setSymbol( info.getSymbol() );
                        if(score.getDefect()!=null)topVo.setWinPercent( StringUtil.getDoubleOne( score.getDefect().doubleValue()*100 )+"" );
                        topVo.setMarketHeat( score.getTrendsInfoResult() );
                        topVo.setEnergyChange( score.getQuantumEnergyComment() );
                        topVo.setCurrencyLiquidity( score.getLiquidityComment() );
                        topVo.setPopularityIndex( score.getPopularityIndicatorComment() );

                        intList.add( (score.getLiquidityScore() != null) ? score.getLiquidityScore().intValue() : 0 );
                        intList.add( (score.getQuantumEnergyScore() != null) ? score.getQuantumEnergyScore().intValue() : 0 );
                        intList.add( (score.getTrendsInfoScore() != null) ? score.getTrendsInfoScore().intValue() : 0 );
                        intList.add( (score.getPopularityIndicatorScore() != null) ? score.getPopularityIndicatorScore().intValue() : 0 );
                        topVo.setAssess( intList );
                        hotList.add( topVo );
                    }
                }
                LogTrace.info("货币诊断排名前5", "monetarydiagnosisTop5货币诊断排名前5接口hbase返回:",null);
            }else {
                for (int i = 0; i < coinRank.getMarketCapRankList().size(); i++) {
                    CmcCurrencyInfo cyInfo = coinRank.getMarketCapRankList().get( i );
                    String grailStr =null;
                    int d=0;
                    while(grailStr==null){
                        grailStr = hbaseBaseQueryComponent.selectByQualifierData( HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_TABLE_NAME
                                , HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_TABLE_FAMILY
                                , HbaseTableUtils.CURRENCY_DIAGNOSIS_SCORE_QUALIFIER
                                , cyInfo.getId() + "@" + (Integer.parseInt(DateUtils.getCurrentDateString())-d)
                        );
                        if (grailStr!=null){
                            break;
                        }
                        d++;
                    }

                    JSONObject json = JSON.parseObject( grailStr );
                    JSONArray advice = null;
                    if (json != null) {
                        Set<String> setString=json.keySet();
                        Iterator it1 = setString.iterator();
                        String lastKey=null;
                        while(it1.hasNext()){
                            lastKey=it1.next()+"";
                        }
                        advice = (JSONArray) json.getJSONArray( lastKey );
                    }

                    if (advice != null) {
                        List<DiagnosisScore> diaList = JSON.parseArray( advice.toJSONString(), DiagnosisScore.class );
                        DiagnosisScore score = diaList.get( diaList.size() - 1 );
                        List<Integer> intList = new ArrayList<>();
                        MoneyDiagnosisTop5Vo topVo = new MoneyDiagnosisTop5Vo();
                        topVo.setScore( score.getDiagnosisScore().toString().substring( 0, 3 ) );
                        CurrencyInfo info = redisCacheComponent.getCurrencyInfo( score.getId() );
                        topVo.setDiagnosisId( score.getId() );
                        topVo.setSymbol( info.getSymbol() );
                        if(score.getDefect()!=null)topVo.setWinPercent( StringUtil.getDoubleOne( score.getDefect().doubleValue()*100 )+"" );
                        topVo.setMarketHeat( score.getTrendsInfoResult() );
                        topVo.setEnergyChange( score.getQuantumEnergyComment() );
                        topVo.setCurrencyLiquidity( score.getLiquidityComment() );
                        topVo.setPopularityIndex( score.getPopularityIndicatorComment() );

                        intList.add( (score.getLiquidityScore() != null) ? score.getLiquidityScore().intValue() : 0 );
                        intList.add( (score.getQuantumEnergyScore() != null) ? score.getQuantumEnergyScore().intValue() : 0 );
                        intList.add( (score.getTrendsInfoScore() != null) ? score.getTrendsInfoScore().intValue() : 0 );
                        intList.add( (score.getPopularityIndicatorScore() != null) ? score.getPopularityIndicatorScore().intValue() : 0 );
                        topVo.setAssess( intList );
                        hotList.add( topVo );
                    }
                }
            }
            redisServer.set( RedisKeysUtils.DIAGNOSIS_Top5_INDEX,JSON.toJSONString( hotList ),300L);
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("货币诊断排名前5",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  null;
    }

    /**
     * 平台币种
     * @param T t
     * @return List<T>
     */
    public ApiResultVo getConceptCurrency() {
        ApiResultVo resultVo=new ApiResultVo();
        JSONObject object=new JSONObject();

        try {
            ConceptCategory conceptCategory=new ConceptCategory();
            conceptCategory.setDeleteFlag( false );
            conceptCategory.setEnableFlag( true );
            List<ConceptCategory> conceptCategoryList =  conceptCategoryMapper.selectByEntityList(conceptCategory);

            Map<String,List<ApiConceptSymbolVo>> resultMap=new HashMap<>(  );
            for (int l=0;l<conceptCategoryList.size();l++){
                List<ApiConceptSymbolVo> symbolVoList=new ArrayList<ApiConceptSymbolVo>();

                String   grailStr = hbaseBaseQueryComponent.selectByQualifierData(HbaseTableUtils.CONCEPTUAL_QUOTES_DETAIL_TABLE_NAME
                        , HbaseTableUtils.CONCEPTUAL_QUOTES_DETAIL_TABLE_NAME_FAMILY
                        , HbaseTableUtils.CONCEPTUAL_QUOTES_DETAIL_QUALIFIER
                        , conceptCategoryList.get( l ).getId()+"@"+DateUtils.getCurrentDateString()
                );
                Long jStart = System.currentTimeMillis();

                if (StringUtils.isNotBlank(grailStr)){
                    JSONArray json = JSON.parseArray( grailStr );
                    LogTrace.info("平台币种jsonarray", "conceptCurrency平台币种接口hbase返回:",json.size()+"");
                    if (json!=null){
                        for(int i=0;i<json.size();i++){
                            JSONObject obj= (JSONObject) json.get(i);
                            ApiConceptSymbolVo bolVo=new ApiConceptSymbolVo();
                            bolVo.setRank(i+1);
                            CurrencyInfo info = redisCacheComponent.getCurrencyInfo(obj.get( "id" ).toString());
                            bolVo.setUrl(info.getImageUrl());
                            if (obj.containsKey("symbol"))bolVo.setSymbol(obj.get("symbol").toString());
                            if (obj.containsKey("marketCapCny"))bolVo.setMarketVolume(Double.parseDouble(obj.get("marketCapCny").toString()));
                            if (obj.containsKey("volume24hCny"))bolVo.setCirculatingSupply(Double.parseDouble(obj.get("volume24hCny").toString()));
                            if (obj.containsKey("volume24hUsd"))bolVo.setVolume24h(StringUtil.getDoubleTwo( Double.parseDouble(obj.get("volume24hUsd").toString()) ));  //成交额度
                            if (obj.containsKey("percentChange24h"))bolVo.setChange(Double.parseDouble(obj.get("percentChange24h").toString()));
                            symbolVoList.add(bolVo);
                        }
                    }
                }
                redisServer.set( RedisKeysUtils.CONCEPT_CURRCY_INDEX+conceptCategoryList.get( l ).getId(),JSON.toJSONString( symbolVoList ),300L);
            }

        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("平台币种",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  null;
    }


    /**
     * 货币搜索唯一性查询
     * @param T t
     * @return List<T>
     */
    public ApiResultVo Uniqueness(CurrencyInfo currencyInfo) {
        ApiResultVo resultVo=new ApiResultVo();
        uniquenessVo uniquenessVo=new uniquenessVo();

        try {
            //币种
            CurrencyInfo info=new CurrencyInfo();
            info.setSymbol( currencyInfo.getCoinNameCn() );
            info.setEnableFlag( true );
            info.setDeleteFlag( false );
            List<CurrencyInfo> infoList=currencyInfoMapper.getUniqueness( info );
            CurrencyInfoTypeVo currencyInfoTypeVo=new CurrencyInfoTypeVo();
            if (infoList.size()==1){
                //唯一
                currencyInfoTypeVo.setSymbol( infoList.get( 0 ).getSymbol() );
                currencyInfoTypeVo.setCmcId( infoList.get( 0 ).getCmcId() );
                currencyInfoTypeVo.setCoinNameCn( infoList.get( 0 ).getCoinNameCn() );
                currencyInfoTypeVo.setType( 1 );
                currencyInfoTypeVo.setDescription( "币种" );
                uniquenessVo.setCurrencyInfoTypeVo( currencyInfoTypeVo );

            }else if(infoList.size()==0){
                //不存在
                currencyInfoTypeVo.setType( 0 );
                currencyInfoTypeVo.setDescription( "币种" );
                uniquenessVo.setCurrencyInfoTypeVo( currencyInfoTypeVo );
            }else if (infoList.size()>1){
                currencyInfoTypeVo.setType( 2 );
                currencyInfoTypeVo.setDescription( "币种" );
                uniquenessVo.setCurrencyInfoTypeVo( currencyInfoTypeVo );
            }

            //交易对
            TransactionPair transactionPair=new TransactionPair();
            transactionPair.setSymbol( currencyInfo.getCoinNameCn() );
            List<TransactionPair> transactionPairList=transactionPairMapper.transactionUniqueness( transactionPair );
            TransactionPairVo transactionPairVo=new TransactionPairVo();
            if(transactionPairList.size()>0){
                //唯一
                transactionPairVo.setId( transactionPairList.get( 0 ).getId() );
                transactionPairVo.setTransactionName( transactionPairList.get( 0 ).getTransactionName());
                transactionPairVo.setEnName( transactionPairList.get( 0 ).getEnName());
                transactionPairVo.setDescription( "交易对" );
                transactionPairVo.setType(1);
                uniquenessVo.setTransactionPairVo( transactionPairVo );
            }else if(transactionPairList.size()==0){
                transactionPairVo.setDescription( "交易对" );
                transactionPairVo.setType(0);
                uniquenessVo.setTransactionPairVo( transactionPairVo );
            }else{
                transactionPairVo.setDescription( "交易对" );
                transactionPairVo.setType(2);
                uniquenessVo.setTransactionPairVo( transactionPairVo );
            }

            ExchangeInfo exchangeInfo=new ExchangeInfo();
            exchangeInfo.setExchangeName( currencyInfo.getCoinNameCn() );
            exchangeInfo.setDeleteFlag( false );
            exchangeInfo.setEnableFlag( true );
            exchangeInfo.setShelfFlag( true );

            List<ExchangeInfo> exchangeInfoList = exchangeInfoDao.exchangeInfoUniqueness( exchangeInfo );
            ExchangeInfoVo exchangeInfoVo=new ExchangeInfoVo();
            if(exchangeInfoList.size()>0){
                exchangeInfoVo.setDescription( "交易所" );
                exchangeInfoVo.setId( exchangeInfoList.get( 0 ).getId() );
                exchangeInfoVo.setExchangeName( exchangeInfoList.get( 0 ).getExchangeName() );
                exchangeInfoVo.setType( 1 );
                uniquenessVo.setExchangeInfoVo( exchangeInfoVo );
            }else if(exchangeInfoList.size()==0){
                exchangeInfoVo.setDescription( "交易所" );
                exchangeInfoVo.setType( 0 );
                uniquenessVo.setExchangeInfoVo( exchangeInfoVo );
            }else{
                exchangeInfoVo.setDescription( "交易所" );
                exchangeInfoVo.setType( 2 );
                uniquenessVo.setExchangeInfoVo( exchangeInfoVo );
            }
            resultVo.setData( uniquenessVo );
            resultVo.setCode(ApiResultCodeUtils.BASE_SUCCESS.getCode());
            resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error("货币搜索唯一性查询",e);
            resultVo.setCode(ApiResultCodeUtils.SYSTEM_ERROR.getCode());
            resultVo.setMessage(ApiResultCodeUtils.SYSTEM_ERROR.getMsg());
            resultVo.setTradeId(LogTrace.getTrace().getTraceId());
            return  resultVo;
        }
        return  resultVo;
    }



}
